import tornado.web import tornado.websocket import tornado.httpserver import tornado.ioloop import time import json import threading class TaskHandler(tornado.websocket.WebSocketHandler): def open(self): pass def check_origin(self, origin): return True def on_message(self, message): try: print 'received: ', message self.write_message(json.dumps({'status': 'running'})) def worker_A(kwargs): time.sleep(100) pass def worker_B(kwargs): time.sleep(100) pass threads = [] for target in [worker_A, worker_B]: t = threading.Thread(target = target, args = ({'xxx': 'yyy'}, )) t.daemon = True t.start() threads.append(t) for t in threads: t.join() except Exception, e: print 'TaskHandler: exception: ', e pass self.write_message(json.dumps({'status': 'done'})) def on_close(self): pass class Server(tornado.web.Application): def __init__(self): handlers = [ ('/task', TaskHandler), ] tornado.web.Application.__init__(self, handlers) if __name__ == '__main__': server = tornado.httpserver.HTTPServer(Server()) server.listen(8765, address = '127.0.0.1') tornado.ioloop.IOLoop.instance().start()--
You received this message because you are subscribed to the Google Groups "Tornado Web Server" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
self.command_queue.put_nowait(new_user)I'm using tornado with threads.In short, each time the websocket handler receives a requests, it start to execute a task, which might take a few minutes.
However, once a client is connected, no other client can be connected, until the first one disconnects.
Hi,
that is because websockets can not do async for now afaik