tornado

Python SyntaxError: ("'return' with argument inside generator",)

Python SyntaxError: ("'return' with argument inside generator",) Question: I have this function in my Python program: @tornado.gen.engine def check_status_changes(netid, sensid): como_url = “”.join([‘http://131.114.52:44444/ztc?netid=’, str(netid), ‘&sensid=’, str(sensid), ‘&start=-5s&end=-1s’]) http_client = AsyncHTTPClient() response = yield tornado.gen.Task(http_client.fetch, como_url) if response.error: self.error(“Error while retrieving the status”) self.finish() return error for line in response.body.split(“n”): if line != “”: #net = …

Total answers: 1

When to use Tornado, when to use Twisted / Cyclone / GEvent / other

When to use Tornado, when to use Twisted / Cyclone / GEvent / other Question: Which of these frameworks / libraries would be the best choise for building modern multiuser web application? I would love to have an asynchronous webserver which will allow me to scale easly. What solution will give the best performance / …

Total answers: 4

How do I return HTTP error code without default template in Tornado?

How do I return HTTP error code without default template in Tornado? Question: I am currently using the following to raise a HTTP bad request: raise tornado.web.HTTPError(400) which returns a html output: <html><title>400: Bad Request</title><body>400: Bad Request</body></html> Is it possible to return just the HTTP response code with a custom body? Asked By: S-K' || …

Total answers: 7

Why use Tornado and Flask together?

Why use Tornado and Flask together? Question: As far as I can tell Tornado is a server and a framework in one. It seems to me that using Flask and Tornado together is like adding another abstraction layer (more overhead). Why do people use Flask and Tornado together, what are the advantages? Asked By: 3k- …

Total answers: 4

How to run functions outside websocket loop in python (tornado)

How to run functions outside websocket loop in python (tornado) Question: I’m trying to set up a small example of a public Twitter stream over websockets. This is my websocket.py, and it’s working. What I’m wondering is: how can I interact with the websocket from ‘outside’ the class WSHandler (ie. not only answer when receiving …

Total answers: 3

Python JSON encoder to support datetime?

Python JSON encoder to support datetime? Question: is there any elegant way to make Python JSON encoder support datetime? some 3rd party module or easy hack? I am using tornado’s database wrapper to fetch some rows from db to generate a json. The query result includes a regular MySQL timestamp column. It’s quite annoying that …

Total answers: 9

Disable static file caching in Tornado

Disable static file caching in Tornado Question: By default, Tornado puts a Cache-Control: public header on any file served by a StaticFileHandler. How can this be changed to Cache-Control: no-cache? Asked By: Jordan || Source Answers: Looking into the tornado/web.py it seems that the easiest way is to subclass the StaticFileHandler and override the set_extra_headers …

Total answers: 2

How to get image size (bytes) using PIL

How to get image size (bytes) using PIL Question: I found out how to use PIL to get the image dimensions, but not the file size in bytes. I need to know the file size to decide if the file is too big to be uploaded to the database. Asked By: Abdelouahab Pp || Source …

Total answers: 5

Tornado URL query parameters

Tornado URL query parameters Question: I’ve been playing around with Tornado, and I’ve written some code that doesn’t seem very nice. I’m writing an app to store recipes as an example. These are my handlers: handlers = [ (r”/recipes/”, RecipeHandler), (r”/recipes”, RecipeSearchHandler), #so query params can be used to search ] This lead me to …

Total answers: 4

How to serve static files from a different directory than the static path?

How to serve static files from a different directory than the static path? Question: I am trying this: favicon_path = ‘/path/to/favicon.ico’ settings = {‘debug’: True, ‘static_path’: os.path.join(PATH, ‘static’)} handlers = [(r’/’, WebHandler), (r’/favicon.ico’, tornado.web.StaticFileHandler, {‘path’: favicon_path})] application = tornado.web.Application(handlers, **settings) application.listen(port) tornado.ioloop.IOLoop.instance().start() But it keeps serving the favicon.ico that I have in my static_path (I …

Total answers: 3