Allow passing multiprocessing.Queues to QueueListener/QueueHandler (#10169)

This commit is contained in:
Alex Waygood
2023-05-10 16:06:41 +01:00
committed by GitHub
parent db0149859c
commit d1bfd08b4b
2 changed files with 23 additions and 6 deletions

View File

@@ -1,6 +1,9 @@
from __future__ import annotations
import logging
import logging.handlers
import multiprocessing
import queue
from typing import Any
# This pattern comes from the logging docs, and should therefore pass a type checker
@@ -16,3 +19,12 @@ def record_factory(*args: Any, **kwargs: Any) -> logging.LogRecord:
logging.setLogRecordFactory(record_factory)
# The logging docs say that QueueHandler and QueueListener can take "any queue-like object"
# We test that here (regression test for #10168)
logging.handlers.QueueHandler(queue.Queue())
logging.handlers.QueueHandler(queue.SimpleQueue())
logging.handlers.QueueHandler(multiprocessing.Queue())
logging.handlers.QueueListener(queue.Queue())
logging.handlers.QueueListener(queue.SimpleQueue())
logging.handlers.QueueListener(multiprocessing.Queue())