mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.12] gh-124653: Relax (again) detection of queue API for logging handlers (GH-124897) (GH-125060)
(cherry picked from commit 7ffe94fb24
)
This commit is contained in:
parent
79b4c9d99a
commit
bc237ed9a8
4 changed files with 78 additions and 55 deletions
|
@ -502,7 +502,7 @@ class BaseConfigurator(object):
|
|||
|
||||
def _is_queue_like_object(obj):
|
||||
"""Check that *obj* implements the Queue API."""
|
||||
if isinstance(obj, queue.Queue):
|
||||
if isinstance(obj, (queue.Queue, queue.SimpleQueue)):
|
||||
return True
|
||||
# defer importing multiprocessing as much as possible
|
||||
from multiprocessing.queues import Queue as MPQueue
|
||||
|
@ -519,13 +519,13 @@ def _is_queue_like_object(obj):
|
|||
# Ideally, we would have wanted to simply use strict type checking
|
||||
# instead of a protocol-based type checking since the latter does
|
||||
# not check the method signatures.
|
||||
queue_interface = [
|
||||
'empty', 'full', 'get', 'get_nowait',
|
||||
'put', 'put_nowait', 'join', 'qsize',
|
||||
'task_done',
|
||||
]
|
||||
#
|
||||
# Note that only 'put_nowait' and 'get' are required by the logging
|
||||
# queue handler and queue listener (see gh-124653) and that other
|
||||
# methods are either optional or unused.
|
||||
minimal_queue_interface = ['put_nowait', 'get']
|
||||
return all(callable(getattr(obj, method, None))
|
||||
for method in queue_interface)
|
||||
for method in minimal_queue_interface)
|
||||
|
||||
class DictConfigurator(BaseConfigurator):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue