tornado

Combine tornado gen.coroutine and joblib mem.cache decorators

流过昼夜 提交于 2019-12-08 12:37:13
问题 Imagine having a function, which handles a heavy computational job, that we wish to execute asynchronously in a Tornado application context. Moreover, we would like to lazily evaluate the function, by storing its results to the disk, and not rerunning the function twice for the same arguments. Without caching the result (memoization) one would do the following: def complex_computation(arguments): ... return result @gen.coroutine def complex_computation_caller(arguments): ... result = complex

How to automatically close connection serverside after a certain time in Tornado Websocket

好久不见. 提交于 2019-12-08 11:46:26
问题 I have a Tornado Websocket server which has a dictionary of open connections: class WebSocketHandler(tornado.websocket.WebSocketHandler): def open(self, *args): self.id = self.generate_id() self.stream.set_nodelay(True) # ... DO STUFF ... clients[self.id] = {"id": self.id, "time":datetime.now(), "object": self} self.write_message("Connection SUCCESSFUL! Thanks for connecting! Your connection ID is: %d :)" % self.id) print datetime.now() print "New connection. ID: %d" % self.id print "Total

supervisord logging tornado errors twice in the stdout

我的未来我决定 提交于 2019-12-08 10:56:17
问题 My supervisord config is the following [supervisord] nodaemon=true logfile=/dev/null logfile_maxbytes=0 logfile_maxbytes=0 ; (max main logfile bytes b4 rotation;default 50MB) logfile_backups=10 ; (num of main logfile rotation backups;default 10) loglevel=info ; (log level;default info; others: debug,warn,trace) user=root group=root [program:tornado] command=python3 tornadoaas.py directory=/tornado_api stdout_logfile=/dev/stdout stdout_logfile_maxbytes=0 stderr_logfile=/dev/stderr stderr

What are the advantages (or needs) of using tornado with Pusher for a Django application?

筅森魡賤 提交于 2019-12-08 08:24:40
问题 We are a small team starting to plan how to develop a chat service in Django using Pusher to push the messages in real time. So far we understand that we need an asynchronous way of pushing the messages to the Android and web browsers clients and we've chosen a hosted solution (Pusher) instead of implementing our own, probably using sockjs and tornado. We thought we didn't need Tornado for anything now that we have Pusher!. In the Python module documentation (https://github.com/pusher/pusher

How does async work in Tornado?

笑着哭i 提交于 2019-12-08 05:22:38
问题 All examples in the Tornado documents show how we can make further HTTP requests asynchronously using Tornado. http_client = httpclient.AsyncHTTPClient() http_client.fetch("http://www.google.com/", handle_request) While I want to ensure that my tornado doesn't wait for response from database (get command of couchbase) to send next. Check my other bug to understand why I want async call to couchbase. 回答1: As far as I know Couchbase driver is not an async driver so this wont work. Make the db

How do you understand the ioloop in tornado?

◇◆丶佛笑我妖孽 提交于 2019-12-08 04:57:46
问题 I am looking for a way to understand ioloop in tornado, since I read the official doc several times, but can't understand it. Specifically, why it exists. from tornado.concurrent import Future from tornado.httpclient import AsyncHTTPClient from tornado.ioloop import IOLoop def async_fetch_future(): http_client = AsyncHTTPClient() future = Future() fetch_future = http_client.fetch( "http://mock.kite.com/text") fetch_future.add_done_callback( lambda f: future.set_result(f.result())) return

Access bokeh server URL

浪子不回头ぞ 提交于 2019-12-08 04:37:29
问题 I'd like to access my bokeh application's URL. I tried: curdoc().session_context.server_context.application_context.url But it only gives me the last part of the URL. Also, when acessing the HTTP request object from curdoc().session_context.request Only the arguments member can be queried (as defined in https://docs.bokeh.org/en/latest/docs/user_guide/server.html#accessing-the-http-request). How do I get the complete URL of the running bokeh application? Thanks 回答1: As suggested in the

Tornado IOLoop Exception in callback None in Celery worker

徘徊边缘 提交于 2019-12-08 04:13:47
问题 I am using tornado.ioloop inside celery worker because I need to use mongodb. class WorkerBase(): @gen.engine def foo(self,args,callback) bar = ['Python','Celery','Javascript','HTML'] # ... process something .... callback(bar) @gen.engine def RunMyTask(self,args): result = yield gen.Task(self.foo,args=args) # Stop IOLoop instance IOLoop.instance().stop() @task(name="MyWorker",base=WorkerBase) def CeleryWorker(args): # This works because i'm adding base as WorkerBase CeleryWorker.RunMyTask

In Tornado, how to do non-blocking file read/write?

时光怂恿深爱的人放手 提交于 2019-12-08 03:54:42
问题 I've been using Tornado for a while now and I've encountered issues with slow timing (which I asked about in this question). One possible issue that was pointed out by a fellow user was that I was using regular open("..." , 'w') to write to files in my co-routine and that this might be a blocking piece of code. So my question is, is there a way to do non-blocking file IO in Tornado? I couldn't find anything in my research that fit my needs. 回答1: Move all of the code associated with file IO to

tornado.web.authenticated back button issue

有些话、适合烂在心里 提交于 2019-12-08 01:57:12
问题 I just added a simple login using tornado.web.authenticated based off of some tutorials online. Unfortunately, after logging out successfully, when I press the back button on my browser, I'm still able to see logged in pages. Is there a way to trigger the login screen for pages in the browsing history? Edit: To clarify, I am already using the @tornado.web.authenticated annotation and it is working well for the normal use cases, but I am running into the issue that when going back using the