This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import websocket | |
import threading | |
import random | |
import time | |
import sys | |
class Worker(threading.Thread): | |
def __init__(self, *args, **kwargs): | |
self.lock = threading.RLock() | |
self.packets_sent = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tornado import web, websocket, ioloop | |
class Test(websocket.WebSocketHandler): | |
clients = set() | |
def open(self): | |
self.clients.add(self) | |
def on_message(self, msg): | |
for c in self.clients: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sent: number of messages sent by one client per second | |
recv: total number of messages received per one second | |
pings: in milliseconds | |
node.js echo server with commented log output: | |
clients: 5, sent: 8759.521709, recv: 43795.308466, min_ping: 0, max_ping: 4, avg_ping: 0.399996, errors: 0 | |
clients: 25, sent: 1998.742675, recv: 49938.586699, min_ping: 0, max_ping: 20, avg_ping: 1.998743, errors: 0 | |
clients: 50, sent: 1051.625850, recv: 52363.271976, min_ping: 0, max_ping: 59, avg_ping: 5.885065, errors: 0 | |
clients: 100, sent: 514.820466, recv: 50273.736734, min_ping: 0, max_ping: 233, avg_ping: 22.884596, errors: 0 | |
clients: 150, sent: 365.081970, recv: 52460.994307, min_ping: 0, max_ping: 473, avg_ping: 46.202689, errors: 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First version: | |
def make_line_iter(iter): | |
buf = '' | |
last_pos = 0 | |
for p in iter: | |
buf += p | |
lb = buf.find('\n', last_pos) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Queue | |
import threading | |
import functools | |
import traceback | |
from tornado.ioloop import IOLoop | |
THREAD_LIMIT = 8 | |
_task_queue = Queue.Queue(THREAD_LIMIT * 2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# With a callback | |
def test(): | |
def handle_user(username, first_name, last_name, exception=None): | |
if exception: | |
# Blow up | |
return | |
print username, first_name, last_name | |
get_user_id(10, handle_user) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Error thrown at line 667, column 4 in <anonymous function: XHRObject.prototype._start>(method, url, payload) in http://cdn.sockjs.org/sockjs-0.2.1.js: | |
that.xhr.send(payload); | |
called from line 615, column 43 in <anonymous function: utils.XHRObject>() in http://cdn.sockjs.org/sockjs-0.2.1.js: | |
that._start(method, url, payload); | |
Uncaught exception: ReferenceError: Security violation | |
Error thrown at line 667, column 4 in <anonymous function: XHRObject.prototype._start>(method, url, payload) in http://cdn.sockjs.org/sockjs-0.2.1.js: | |
that.xhr.send(payload); | |
called from line 615, column 43 in <anonymous function: utils.XHRObject>() in http://cdn.sockjs.org/sockjs-0.2.1.js: | |
that._start(method, url, payload); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> | |
<script src="http://cdn.sockjs.org/sockjs-0.1.2.min.js"></script> | |
<script> | |
$(function() { | |
var conn = null; | |
function log(msg) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
""" | |
Simple sockjs-tornado chat application. By default will listen on port 8080. | |
""" | |
import tornado.ioloop | |
import tornado.web | |
import sockjs.tornado | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sqlalchemy import create_engine | |
from sqlalchemy.orm import scoped_session, sessionmaker | |
# Simple database and session wrapper. I use it in my Flask app too. | |
class Database(object): | |
def __init__(self): | |
self.session_maker = sessionmaker() | |
self.session = scoped_session(self.session_maker) | |
self.engine = None |
OlderNewer