bnopne
bnopne

Reputation: 95

Tornado Ioloop in thread

I need to implement a simple service using Tornado. When my service starts it creates a second thread and i need to run Tornado's ioloop in this thread, because meanwhile the main thread is busy doing some other work. Is it ok to get ioloop instance using IOLoop.current() in second thread or there is another way to get ioloop instance for the thread? Docs say that current() returns main threads's ioloop instance if there's no running ioloop in current thread. I am a little confused at this point.

Upvotes: 2

Views: 2609

Answers (1)

A. Jesse Jiryu Davis
A. Jesse Jiryu Davis

Reputation: 24007

I see that the documentation is confusing. When your background thread begins, run this on the background thread:

io_loop = IOLoop()
io_loop.make_current()

After that, IOLoop.current(instance=False) on the background thread will return the thread's special IOLoop.

Upvotes: 4

Related Questions