I run python apscheduler and periodically want to do some POST-ing work on some http resources, which will include using the AsyncHttpClient tornado as a scheduled task. Each work will perform several POST. When each HTTP request responds, then a callback is called (I think Tornado uses future to accomplish this).
I am worried about thread safety here, since apscheduler runs jobs on different threads. I could not find a well-explained example of how tornadoes are best used in multiple threads in this context.
How can I best use apscheduler with tornado this way?
Specific problems:
What tornado should i use? The docs say that AsyncHttpClient "works like magic." Well, magic scares me. Do I need to use AsyncHttpClient from the current thread, or can I use the main one (you can specify it)?
Are there any thread safety issues with my callback that I am using?
It is not clear what happens when the thread terminates, but there is still a pending callback / future that needs to be called. Is there a problem here?
Since apscheduler starts as threads in a process, and python has a GIL, is it almost the same as one IOLoop from the main thread - unlike several loops from different threads (relative to performance)?
source share