Queue_handler = QueueHandler(log_queue) # Non-blocking handler. Async code won't experience any blocking behavior from the logging system.įor example, a QueueHandler can be set up as the root handler import queueįrom logging.handlers import QueueHandler The solution below is entirely compatible with coroutines that call up the logging loggers and submit entries in typical fashion - wrappers with calls to. Pureism aside, there's no hard-bound rule that precludes the use of the QueueHandler for providing async code that logs with a non-blocking log handler, used together with a blocking handler hosted in a QueueListener. There's a simple solution for this provided by the standard logging module: use a non-blocking handler that enqueues its messages to the desired blocking handler running in its own private thread. This can happen if a blocking handler that writes to file is added directly somewhere along the logging hierarchy. The concern here is whether submitting log entries will incur some delay while the entries are written to file, depriving the asynchronous system the opportunity to run other tasks during the lapse. Logging.getLogger(_name_).warn("Things went awry.") Logging.getLogger(_name_).info("Started doing stuff.") Async code can use the usual logging features without resorting to special async modules or wrappers.
0 Comments
Leave a Reply. |