tornado

Missing OAuth request token cookie error using tornado and TwitterMixin

你说的曾经没有我的故事 提交于 2019-12-12 10:25:23
问题 I'm using tornado and the TwitterMixin and I use the following basic code: class OauthTwitterHandler(BaseHandler, tornado.auth.TwitterMixin): @tornado.web.asynchronous def get(self): if self.get_argument("oauth_token", None): self.get_authenticated_user(self.async_callback(self._on_auth)) return self.authorize_redirect() def _on_auth(self, user): if not user: raise tornado.web.HTTPError(500, "Twitter auth failed") self.write(user) self.finish() For me it works very well but sometimes, users

Tornado celery can't use gen.Task or CallBack

自作多情 提交于 2019-12-12 09:41:10
问题 class AsyncHandler(tornado.web.RequestHandler): @tornado.web.asynchronous def get(self): tasks.sleep.apply_async(args=[5], callback=self.on_result) def on_result(self, response): self.write(str(response.result)) self.finish() raise error : raise TypeError(repr(o) + " is not JSON serializable") TypeError: <bound method AsyncHandler.on_result of <__main__.AsyncHandler object at 0x10e7a19d0>> is not JSON serializable The broker and backends all use redis, I just copied from https://github.com

How non-blocking web server works?

耗尽温柔 提交于 2019-12-12 06:47:03
问题 I'm trying to understand the idea of non-blocking web server and it seems like there is something I miss. I can understand there are several reasons for "block" web request(psuedocode): CPU bound string on_request(arg) { DO_SOME_HEAVY_CPU_CALC return "done"; } IO bound string on_request(arg) { DO_A_CALL_TO_EXTERNAL_RESOURCE_SUCH_AS_WEB_IO return "done"; } sleep string on_request(arg) { sleep(VERY_VERY_LONG_TIME); return "done"; } are all the three can benefit from non-blocking server? how the

Saving API output async using SQLAlchemy and Tornado

倖福魔咒の 提交于 2019-12-12 05:01:54
问题 I want to save the output of a currency API in a MySQL table using SQLAlchemy and Tornado but when I loop over the JSON results the API returned and I insert each one to the database, the app get stuck. No other procedures can be executed until all inserts are completed when this happens. I guess I should execute the insert also as a coroutine but not sure how to do that. I know there are several libraries for async SQLAlchemy such as Asyncio but are they really needed when using Tornado? The

ERROR:tornado.general:Could not open static file

一个人想着一个人 提交于 2019-12-12 04:44:19
问题 I'm writing a tornado web app and have a file named "static" with files such as main.js, require.js, elasticsearch.js, and d3.v3.js. The last three are just source code for the javascript libraries. In my index.html file I have the lines <script>src={{ static_url("scripts/require.js") }}></script> <script>require([{{ static_url("scripts/main.js") }}], function () {})</script> Now when I run the app, I get two errors: ERROR:tornado.general:Could not open static file '...' for each of my two

Make Tornado able to handle new requests while waiting response from RPC over RabbitMQ

巧了我就是萌 提交于 2019-12-12 04:36:50
问题 I have web-server listening clients and when someone hit handler server send an RPC message to RabbitMQ and waiting for response while keeping connection. When response from RMQ came server pass it to the client as response to request. All async examples in Tornado docs works with their own http.fetch_async() or something like that methods, and I understand that I have to wait/read for RMQ asynchronously... But how? And even worse - sometimes I have to send several messages at one moment (I

tornado Python: Tornado server integration with NGINX

左心房为你撑大大i 提交于 2019-12-12 04:10:51
问题 I am trying to run Tornado on multicore CPU with each tornado IOLoop process on a different core, and I'll use NGINX for proxy pass to Tornado processes. Now when I check http://www.tornadoweb.org/en/stable/guide/running.html Editing the actual configuration here for more details: events { worker_connections 1024; } http { upstream chatserver { server 127.0.0.1:8888; } server { # Requires root access. listen 80; # WebSocket. location /chatsocket { proxy_pass http://chatserver; proxy_http

【tornado建站】搜索博客内容

十年热恋 提交于 2019-12-12 04:07:37
博客还需要添加一个搜索博客内容的模块,类已经在最开始的框架中定义,并且需要调用到上一篇文章的模块cut_pages来实现搜索内容的分页,实际上于上一篇文章实现的 功能较为类似。 class SearchHandler(tornado.web.RequestHandler): def get(self, page_index): try: results, pages, page_infos = cut_pages(page_index, "query") self.render('blog_title.html', entrys=results, page_num=int(pages), page_infos=page_infos) except: self.redirect("/index") def post(self): query = self.get_argument('query') query = query + "0" self.redirect("/query/" + query) 代码如上,需要一个get功能,一个post功能用来接收表单,在get功能中调用cut_pages实现搜索博客内容,然后分页展示,如果没有搜索到内容则会重定向到主页。 然后是post表单功能,该post会接收前端的表单,前端代码如下: <form method="post" action

Design of asynchronous request and blocking processing using Tornado

ぐ巨炮叔叔 提交于 2019-12-12 04:02:57
问题 I'm trying to implement a Python app that uses async functions to receive and emit messages using NATS, using a client based on Tornado. Once a message is received, a blocking function must be called, that I'm trying to implement on a separate thread, to allow the reception and publication of messages to put messages in a Tornado queue for later processing of the blocking function. I'm very new to Tornado (and to python multithreading), but after reading several times the Tornado

Why asyncio's run_in_executor blocks tornado's get handler?

五迷三道 提交于 2019-12-12 03:46:45
问题 I want to run a slow blocking method (actually from a 3rd-party library) in tornado's async GET request handler. Let the method be just: def blocking_method(uid): print("slow method started: ", uid) time.sleep(10) print("slow method done: ", uid) return "slow method ({}) result".format(uid) Moreover, I prefer running the tornado server in asyncio's event loop: if __name__ == '__main__': tornado.platform.asyncio.AsyncIOMainLoop().install() loop = asyncio.get_event_loop() loop.run_until