tornado

python - tornado not redirecting to new dummy page

馋奶兔 提交于 2019-12-11 14:14:16
问题 I am using tornado and here is the code for my main handler - class MainHandler(tornado.web.RequestHandler): def get(self): self.render("homepage.html", messages=ChatSocketHandler.browser_cache) # # HTTP *POST* HANDLER # def post(self): print "Post received" post_body = self.get_argument("body") self.set_header("Content-Type", "text/plain") self.redirect("test.html") The test.html file is simple - <!DOCTYPE html> <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> <

Openshift Tornado WebSocket(Demo) not responding

偶尔善良 提交于 2019-12-11 13:37:41
问题 I am trying to host websocket app in python on openshift I found this repo: https://github.com/ramr/openshift-tornado-websockets which uses tornado for websocket and normal HTTP connection, i want to deal with both ws and http,I have successfully deployed the code over openshift. as per the code in binds to default internal port 8000 of openshift, but when i tried connect to ws://piot-cloudap.rhcloud.com:8000/ws-echo/ url end using python websocket client lib, it do connects to the ws URL,

Start pdb on exception in Tornado's ioloop

烂漫一生 提交于 2019-12-11 13:22:23
问题 It's often useful to do this in standalone Python programs: def excepthook(typ, value, tb): traceback.print_exception(typ, value, tb) pdb.pm() ... if log.getEffectiveLevel() == logging.DEBUG: sys.excepthook = excepthook (i.e. if uncatched exception happens, program is dropped into pdb post-mortem mode) But that doesn't work with Tornado ioloop bc it seems that ioloop catches uncatched exceptions and prints or logs them. If I install above hook, the program enters post-mortem mode only on

python3 tornado api + angular8 + nginx 跨域问题

余生颓废 提交于 2019-12-11 12:29:11
问题: 上一个博客部署好了api之后,前端开始吊发现了跨域的问题。 接口地址: http://111.231.201.164/api/houses 服务器上使用的事nginx转发 数据是: 前端angular请求 this.http.get('http://111.231.201.164/api/houses').subscribe((res: any) => { console.log(res); }); 目前测试用的Google 和 Firefox两个。 Google 浏览器 需要注意的事我的Google浏览器已经配置过跨域,就是说服务器的代码无论可不可以跨域我的浏览器都可以访问api。 此时还没在后台或者nginx配置跨域。 Firefox 浏览器 而Firefox还是一如既往跨域问题 解决: 1、我先是配置的tornado,虽然没有鸟用 这是网上大部分的教程,都是如此说的,但是却没有起作用。 class BaseHandler(tornado.web.RequestHandler): # blog.csdn.net/moshowgame 解决跨域问题 def set_default_headers(self): self.set_header("Access-Control-Allow-Origin", "*") # 这个地方可以写域名 self.set_header(

Does Motorengine mantain an IO stream with mongo db?

萝らか妹 提交于 2019-12-11 12:14:10
问题 I want to use Motorengine for my Tornado application. As given in the docs, this is how I am supposed to make the ODM from motorengine.document import Document from motorengine.fields import StringField, DateTimeField class Article(Document): title = StringField(required=True) description = StringField(required=True) published_date = DateTimeField(auto_now_on_insert=True) new_title = "Better Title %s" % uuid4() def create_article(): Article.objects.create( title="Some Article", description=

Why does Tornado spend time in socket.send(data)?

白昼怎懂夜的黑 提交于 2019-12-11 12:06:32
问题 I'm looking at profiles for my Tornado TCP application and I'm finding that the thread running the event loop spends about 20% time in tornado/iostream.py::write_to_fd in the line self.socket.send(data) and about 15% time in tornado/iostream.py::read_from_fd in the line self.socket.recv_into(buf) . Given that these are non-blocking sockets, why does this take any time at all? What are common situations for this to take time and are there any common optimizations I can do to my application to

How to listen for event of closed stdin in a tornado loop?

只谈情不闲聊 提交于 2019-12-11 11:46:00
问题 This is a follow-up question on handling the data in the socket. However, I am unable to capture the "stdin closed" event. Here's what I have now: import sys import tornado from tornado.ioloop import IOLoop from tornado.web import Application, RequestHandler class MainHandler(RequestHandler): def get(self): self.finish("foo") application = Application([ (r"/", MainHandler), ]) @tornado.gen.coroutine def close_callback(*args, **kwargs): print args, kwargs if __name__ == "__main__": application

Tornado Install Issue

我是研究僧i 提交于 2019-12-11 11:24:40
问题 I'm trying to install tornado (pip install tornado) and am getting the following error... Command /usr/bin/python -c "import setuptools, tokenize;__file__='/tmp/pip_build_username/tornado/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-TLunUn-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_username/tornado Traceback (most recent call

Tornado static files serving url configuration

百般思念 提交于 2019-12-11 10:13:21
问题 I configured torando for serving static files for development purposes. settings = { 'template_path': 'templates', 'static_path': 'static' } Inside my template files I am using static_url() to give proper path to my static files. Because my html files have structure of static files already defined tornado static_url isn't showing correct path. For example, on my server file is having url like <link href="/myflz/resources/css/bootstrap.css" rel="stylesheet"/> and after using static_url it is

Requests not being distributed across gunicorn workers

﹥>﹥吖頭↗ 提交于 2019-12-11 10:03:18
问题 I'm trying to write an app using tornado with gunicorn handling the worker threads. I've created the code shown below, but despite starting multiple workers it isn't sharing the requests. One worker seems to process all of the requests all of the time (not intermittent). Code: from tornado.web import RequestHandler, asynchronous, Application from tornado.ioloop import IOLoop import time from datetime import timedelta import os class MainHandler(RequestHandler): def get(self): print "GET start