tornado

Tornado non-blocking SMTP client

若如初见. 提交于 2019-12-07 08:57:05
问题 I'am looking for python async SMTP client to connect it with Torando IoLoop. I found only simple implmementation (http://tornadogists.org/907491/) but it's a blocking solution so it might bring performance issues. Does anyone encountered non blocking SMTP client for Tornado? Some code snippet would be also very useful. 回答1: I wrote solution based on threads and queue. One thread per tornado process. This thread is a worker, gets email from queue and then send it via SMTP. You send emails from

How does 'yield' work in tornado when making an asynchronous call?

穿精又带淫゛_ 提交于 2019-12-07 06:53:50
问题 Recently, I was learning Introduction to Tornado , and I came across the following code: class IndexHandler(tornado.web.RequestHandler): @tornado.web.asynchronous @tornado.gen.engine def get(self): query = self.get_argument('q') client = tornado.httpclient.AsyncHTTPClient() response = yield tornado.gen.Task(client.fetch, "http://search.twitter.com/search.json?" + \ urllib.urlencode({"q": query, "result_type": "recent", "rpp": 100})) body = json.loads(response.body) [...omitted the following

Tornado Error Handling

我的梦境 提交于 2019-12-07 06:07:28
问题 I want to be able to handle a nicer error that's displayed if i type an incorrect URL E.g. localhost:8000/AFDADSFDKFADS I get an ugly python traceback message because a tornado.web.HTTPError exception is thrown. I know I can use a regex to catch all scenarios other than my proper URLs however I figure there must be a way to handle this error within Tornado. I know that I can use the write_error() when extending the tornado.web.RequestHandler but because this error is happening in the tornado

Flask app hangs while processing the request

爷,独闯天下 提交于 2019-12-07 03:54:26
问题 I have a simple flask app, single page, upload html and then do some processing on it on the POST; at POST request; i am using beautifulsoup, pandas and usually it takes 5-10 sec to complete the task. at the end i export the resultant dataframe to excel with pandas(with the update of the previous stored excel if present). and on GET request i return the result of this dataframe. Now issue is... app gives no response while those 5-10 sec.; even if i visit my app from another computer; it will

Telegram bot api keyboard

孤人 提交于 2019-12-07 02:50:40
问题 I have problem with Telegram Bot Api and with "ReplyKeyboard". I'm using Python 2.7 and I send post request: TelegramAPI.post(TELEGRAM_URL + "sendMessage", data=dict(chat_id=CHAT_ID, text="", keyboard={'keyboard': keyboard, 'one_time_keyboard': False, 'resize_keyboard': True}) keyboard in this format: [["A button"], ["B button"]] But in Telegram I don't see keyboard. What problem can be? 回答1: According to the Bot API documentations, a custom keyboard requires a reply_markup parameter, whose

Tornado graceful shutdown of IOLoop

扶醉桌前 提交于 2019-12-07 01:47:07
问题 I'm using the following code to close down my tornado application gracefully (taken from https://gist.github.com/wonderbeyond/d38cd85243befe863cdde54b84505784): def sig_handler(servers, sig, frame): io_loop = tornado.ioloop.IOLoop.instance() def stop_loop(deadline): now = time.time() if now < deadline and (io_loop._callbacks or io_loop._timeouts): logging.info('Waiting for next tick') print("CALL BACKS") print(io_loop._callbacks) print("TIMEOUTS") print(io_loop._timeouts) io_loop.add_timeout

supervisord environment variables setting up application

送分小仙女□ 提交于 2019-12-07 01:38:32
问题 I'm running an application from supervisord and I have to set up an environment for it. There are about 30 environment variables that need to be set. I've tried putting all on one big environment= line and that doesn't seem to work. I've also tried multiple enviroment= lines, and that doesn't seem to work either. I've also tried both with and without ' around the env value. What's the best way to set up my environment such that it remains intact under supervisord control? Should I be calling

利用nginx做tornado的反向代理

萝らか妹 提交于 2019-12-06 16:53:07
1.tornado的demo 首先写一个tornado的demo 在生产环境中,一般使用单个的进程启动,为了简单起见,这里我们使用multiprocessing模块启动多个进程,模拟生产环境 #!/usr/bin/python #-*-encodeing:utf-8-*- import tornado.web import tornado.ioloop import tornado.options import multiprocessing from tornado.options import define,options import os,sys define("port", default=9000, help="run on the given port", type=int) class BaseHandler(tornado.web.RequestHandler): def get_current_user(self): return self.get_secure_cookie('user') def get_template_path(self): return os.path.join(os.path.dirname(__file__),'templates') class MainHandler(BaseHandler): @tornado.web

What are the advantages (or needs) of using tornado with Pusher for a Django application?

大兔子大兔子 提交于 2019-12-06 15:51:02
We are a small team starting to plan how to develop a chat service in Django using Pusher to push the messages in real time. So far we understand that we need an asynchronous way of pushing the messages to the Android and web browsers clients and we've chosen a hosted solution (Pusher) instead of implementing our own, probably using sockjs and tornado. We thought we didn't need Tornado for anything now that we have Pusher!. In the Python module documentation ( https://github.com/pusher/pusher_client_python ) there is only small mention to Django, there is however a Tornado section which says:

Tornado IOLoop Exception in callback None in Celery worker

空扰寡人 提交于 2019-12-06 15:30:58
I am using tornado.ioloop inside celery worker because I need to use mongodb. class WorkerBase(): @gen.engine def foo(self,args,callback) bar = ['Python','Celery','Javascript','HTML'] # ... process something .... callback(bar) @gen.engine def RunMyTask(self,args): result = yield gen.Task(self.foo,args=args) # Stop IOLoop instance IOLoop.instance().stop() @task(name="MyWorker",base=WorkerBase) def CeleryWorker(args): # This works because i'm adding base as WorkerBase CeleryWorker.RunMyTask(args) IOLoop.instance().start() return True When I am invoking a task it gives an error saying: [2014-10