Riz
Riz

Reputation: 348

Writing to log files in a non-blocking manner in Tornado/Python

I am using Tornado for a websockets server and I am trying to figure out how to log to a file without blocking the main thread. Is tornado.log non-blocking? If not, is there a general pythonic way to log to a file without blocking the main thread?

Thanks!

Upvotes: 1

Views: 532

Answers (1)

Ben Darnell
Ben Darnell

Reputation: 22154

Tornado uses the standard library's logging module, which is blocking in most configurations. Python 3.2 includes a QueueHandler class which can be used to move the actual I/O to a separate thread; prior to that there was no standard solution to non-blocking logging (but there's probably a package on PyPI with a 2.x-compatible implementation).

Upvotes: 1

Related Questions