I am running python's apscheduler
and periodically want to do some work POST-ing to some http resources which will involve using tornado's AsyncHttpClient
as a scheduled job. Each job will do several POSTs. When each http request responds a callback is then called (I think that Tornado uses a future
to accomplish this).
I am concerned with thread-safety here since Apscheduler
runs jobs in various threads. I have not been able to find a well explained example of how tornado would best be used across multiple threads in this context.
How can I best use apscheduler
with tornado
in this manner?
Specific concerns:
Which tornado ioloop to use? The docs say that
AsyncHTTPClient
"works like magic". Well, magic scares me. Do I need to useAsyncHTTPClient
from within the current thread or can I use the main one (it can be specified)?Are there thread-safety issues with my callback with respect to which ioloop I use?
Not clear to me what happens when a thread completes but there is still a pending callback/future that needs to be called. Are there issues here?
Since apscheduler is run as threads in-process, and python has the GIL, then is it pretty much the same to have one IOLoop from the main thread - as opposed to multiple loops from different threads (with respect to performance)?