--
You received this message because you are subscribed to a topic in the Google Groups "Tornado Web Server" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/python-tornado/iFtV0ni8LBA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to python-tornad...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
@tornado.gen.coroutinedef process_msgs():url = 'ws://localhost:8000/ws'client = tornado.httpclient.HTTPRequest(url)conn = yield tornado.websocket.websocket_connect(client, on_message_callback=put)print 'before sleep'time.sleep(60)print 'after sleep'
tornado.ioloop.IOLoop.instance().run_sync(process_msgs)I start the server and then the client. I get the following output when the client starts.Server:before write_message()after write_message()Client:before sleep
--
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.
import time
import tornado.ioloopimport tornado.webimport tornado.websocketclass WebSocketHandler(tornado.websocket.WebSocketHandler):def open(self, *args):
self.write_message('test')def on_message(self, message):time.sleep(0.2)self.write_message(message)if __name__ == '__main__':
app = tornado.web.Application([(r'/ws', WebSocketHandler),])
app.listen(8000)tornado.ioloop.IOLoop.instance().start()
import timeimport threadingfrom concurrent.futures import ThreadPoolExecutorimport tornadoimport tornado.websocketexecutor = ThreadPoolExecutor(1)def process_msgs():print 'before sleep'time.sleep(1)print 'after sleep'class Client(threading.Thread):def __init__(self):super(self.__class__, self).__init__()self.start()def put(self, msg):
print 'put(): msg=%s' % `msg`
self.conn.write_message(msg)@tornado.gen.coroutinedef process_msgs(self):
url = 'ws://localhost:8000/ws'
self.conn = yield tornado.websocket.websocket_connect(url, on_message_callback=self.put)yield executor.submit(process_msgs)def run(self):tornado.ioloop.IOLoop.instance().run_sync(self.process_msgs)print 'after tornado.ioloop.IOLoop.instance'client = Client()
before sleepput(): msg=u'test'put(): msg=u'test'put(): msg=u'test'put(): msg=u'test'put(): msg=u'test'after sleepafter tornado.ioloop.IOLoop.instance
executor = ThreadPoolExecutor(1)class Client(threading.Thread):def __init__(self):super(self.__class__, self).__init__()self.start()def put(self, msg):
print 'put(): msg=%s' % `msg`
self.conn.write_message(msg)def process_msgs(self):print 'before sleep'time.sleep(1)print 'after sleep'@tornado.gen.coroutinedef process_msgs(self):
url = 'ws://localhost:8000/ws'
self.conn = yield tornado.websocket.websocket_connect(url, on_message_callback=self.put)yield executor.submit(self.process_msgs)def run(self):tornado.ioloop.IOLoop.instance().run_sync(self.process_msgs)print 'after tornado.ioloop.IOLoop.instance'client = Client()
put(): msg=u'test'after tornado.ioloop.IOLoop.instance
executor = ThreadPoolExecutor(1)def process_msgs(client):print 'before client.process_msgsx'client.process_msgsx()print 'after client.process_msgsx'class Client(threading.Thread):def __init__(self):super(self.__class__, self).__init__()self.start()def put(self, msg):
print 'put(): msg=%s' % `msg`
self.conn.write_message(msg)def process_msgsx(self):print 'before sleep'time.sleep(1)print 'after sleep'@tornado.gen.coroutinedef process_msgs(self):
url = 'ws://localhost:8000/ws'
self.conn = yield tornado.websocket.websocket_connect(url, on_message_callback=self.put)#yield executor.submit(process_msgs)#yield executor.submit(self.process_msgs)yield executor.submit(process_msgs, self)def run(self):tornado.ioloop.IOLoop.instance().run_sync(self.process_msgs)print 'after tornado.ioloop.IOLoop.instance'client = Client()
before client.process_msgsxbefore sleepput(): msg=u'test'put(): msg=u'test'put(): msg=u'test'put(): msg=u'test'put(): msg=u'test'after sleepafter client.process_msgsxafter tornado.ioloop.IOLoop.instance
before client.process_msgsput(): msg=u'test'after client.process_msgsafter tornado.ioloop.IOLoop.instance