tornado

Tornado multiple IOLoop in multithreads

折月煮酒 提交于 2019-12-11 03:42:26
问题 I am trying to run multiple IOLoop in multiple threads and I am wondering how the IOLoop actually works. class WebThread(threading.Thread): def __init__(self): threading.Thread.__init__(self, name='WebThread') def run(self): curdir = os.path.dirname(os.path.realpath(__file__)) application = Application() #Very simple tornado.web.Application http_server_api = tornado.httpserver.HTTPServer(application) http_server_api.listen(8888) logging.info('Starting application') #tornado.ioloop.IOLoop

How to make a library asynchronous in python

陌路散爱 提交于 2019-12-11 03:36:48
问题 In my job they "leverage" tornado but they have no asynchronous libraries. What makes a library asynchronous so that it can be better suited to something like tornado? Are there any good examples or I guess is there somthing you do in __enter__ or __exit__ that can signal that you are not blocking? I'm finding it difficult to scratch together some materials. 回答1: If your libraries are not asynchronous and do not support being run in the tornado ioloop, then the only thing you can do is run

Tornado has correct request body, but cannot find correct arguments

我是研究僧i 提交于 2019-12-11 03:17:20
问题 Making a pretty straightforward Tornado app, but something that seems impossible is happening based on my understanding of Tornado. In short I've got the following RequestHandler : class CreateUserHandler(tornado.web.RequestHandler): def post(self): print self.request.body print self.get_body_argument("email") # Do other things And the following is what is printed: {"email":"slater@indico.io","password":"password"} WARNING:tornado.general:400 POST /user/create/ (::1): Missing argument email

Async function call with Tornado Python

牧云@^-^@ 提交于 2019-12-11 02:47:22
问题 I'm trying to make a simple async call, using gen.coroutine function of Tornado. This is my current code: from tornado import gen import tornado.ioloop import tornado.web class MainHandler(tornado.web.RequestHandler): @gen.coroutine def get(self): q = self.get_argument('query') print q response = yield self.process(q) self.write(response) @gen.coroutine def process(self, query): # just a long loop for i in range(int(query)*100): for j in range(i): a = 10*10*10*10*10*10 return {'processed':

Tornado: DummyFuture does not support blocking for results

断了今生、忘了曾经 提交于 2019-12-11 02:32:38
问题 I am trying to get a very simple initial server which fetches a url (asynchronously) to work but it throws: Exception: DummyFuture does not support blocking for results There's this SO post but the answers do not include running a web server and trying to add the future to my loop as shown here throws: RuntimeError: IOLoop is already running This is the complete code: import tornado.web import tornado.gen from tornado.httpclient import AsyncHTTPClient from tornado.ioloop import IOLoop URL =

Tornado web server works bad with AngularJS operator expression

六月ゝ 毕业季﹏ 提交于 2019-12-11 02:18:17
问题 I run code ( get from http://plnkr.co/edit/WHcjcEHdny0yhM2Rs95d?p=preview) on 2 different server - Tornado and Apache. index.html: <!DOCTYPE html> <html ng-app="contestantApp"> <head> <script data-require="angular.js@1.3.0" data-semver="1.3.0" src="//code.angularjs.org/1.3.0/angular.js"></script> <script src="/static/js/script.js"></script> </head> <body > <h1>Contestants</h1> <section ng-controller="ContestantsCtrl as ctrl"> <ul> <li ng-repeat="contestant in ctrl.contestants"> {{contestant

Making Tornado websocket handler thread safe

二次信任 提交于 2019-12-11 01:05:27
问题 I am randomly getting error 1006 ( (I failed the WebSocket connection by dropping the TCP connection) when trying to write messages from threads using Tornado's websocket server handler. I created N threads and passed my ws_handler to them. But when I start using self.ws_handler.write_message(jsondata) for a large number of threads, I keep getting the same error. From what I understand, 1006 is TCP connection dropped when a 'heartbeat' communication is skipped between websockets. I am

How to log HTTP response in Tornado?

怎甘沉沦 提交于 2019-12-11 00:58:43
问题 I want to be able to log HTTP request and response in tornado. This seems to be easy to do with request: def log_function(handler): info = { 'Method' : handler.request.method, 'Host' : handler.request.host, 'URL' : handler.request.uri } How can the same thing be achieved for response? The response status_code can be retrieved by calling handler.get_status() How do I get a body of a response? 回答1: Tornado doesn't save the response; it sends it directly to the client. If you want to log the

Extending tornado.gen.Task

蓝咒 提交于 2019-12-11 00:08:55
问题 Here's the interesting bits of a stupid websocket clock: class StupidClock(websocket.WebSocketHandler): clients = {} @web.asynchronous @gen.coroutine def open(self): self.is_open = True def enqueue(callback=None): self.__class__.clients[self] = callback while self.is_open: # This is the most interesting part! msg = yield gen.Task(enqueue) self.write_message(msg) def on_close(self): self.is_open = False del self.__class__.clients[self] @classmethod def periodic_update(cls): msg = time.time() #

Spyder-IDE fails to start on Windows-10 with Python-3.8

…衆ロ難τιáo~ 提交于 2019-12-10 23:09:13
问题 checking out Python-3.8.0 (x64) on Windows-10, I got into trouble when trying to setup Spyder . Note: the issue was reproducible with a fresh Python installation on a clean Windows-10 system. However, no such issues on Linux (tested on debian/Mint). At first, everything went smooth during installation via pip install spyder . error #1: pywin32 After starting Spyder , it said in the IPython console window: Traceback (most recent call last): File "c:\users\USERNAME\appdata\local\programs\python