Python SyntaxError: (“‘return’ with argument inside generator”,)

You cannot use return with a value to exit a generator in Python 2, or Python 3.0 – 3.2. You need to use yield plus a return without an expression: if response.error: self.error(“Error while retrieving the status”) self.finish() yield error return In the loop itself, use yield again: for line in response.body.split(“\n”): if line != … Read more

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

You could call a IOLoop.add_timeout(deadline, callback) that calls the callback at specified deadline timeout (one shot, but you can reschedule), or use the tornado.ioloop.PeriodicCallback if you have a more periodic task. See: http://www.tornadoweb.org/en/stable/ioloop.html#tornado.ioloop.IOLoop.add_timeout Update: some example import datetime def test(): print “scheduled event fired” … if __name__ == “__main__”: http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8888) main_loop = … Read more

How to set React to production mode when using Gulp

2017 – Edit: anyone trying to set up React in Gulp for a new project: Just use create-react-app Step I: Add the following to your gulpfile.js somewhere gulp.task(‘apply-prod-environment’, function() { process.env.NODE_ENV = ‘production’; }); Step II: Add it to your default task (or whichever task you use to serve/build your app) // before: // gulp.task(‘default’,[‘browsersync’,’watch’], … Read more

Tornado request.body

As an alternative to Eloim’s answer, Tornado provides tornado.escape for “Escaping/unescaping HTML, JSON, URLs, and others”. Using it should give you exactly what you want: data = tornado.escape.json_decode(self.request.body)

tech