Repository navigation
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Related bug: #111615
Related pull: #111638
Related codes:
Lines 789 to 804 in bd0d97c
| if 'queue' in config: | |
| from multiprocessing.queues import Queue as MPQueue | |
| qspec = config['queue'] | |
| if not isinstance(qspec, (queue.Queue, MPQueue)): | |
| if isinstance(qspec, str): | |
| q = self.resolve(qspec) | |
| if not callable(q): | |
| raise TypeError('Invalid queue specifier %r' % qspec) | |
| q = q() | |
| elif isinstance(qspec, dict): | |
| if '()' not in qspec: | |
| raise TypeError('Invalid queue specifier %r' % qspec) | |
| q = self.configure_custom(dict(qspec)) | |
| else: | |
| raise TypeError('Invalid queue specifier %r' % qspec) | |
| config['queue'] = q |
reproducible example using Python 3.12.3
import logging.config
def main(q):
config = {
'version': 1,
'handlers': {
'sink': {
'class': 'logging.handlers.QueueHandler',
'queue': q,
},
},
'root': {
'handlers': ['sink'],
},
}
logging.config.dictConfig(config)
if __name__ == '__main__':
import multiprocessing as mp
main(mp.Manager().Queue())
#import asyncio
#main(asyncio.Queue()) # broken tooerror:
Traceback (most recent call last):
File "/usr/lib/python3.12/logging/config.py", line 581, in configure
handler = self.configure_handler(handlers[name])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.12/logging/config.py", line 801, in configure_handler
raise TypeError('Invalid queue specifier %r' % qspec)
TypeError: Invalid queue specifier <AutoProxy[Queue] object, typeid 'Queue' at 0x7f8b07189d90>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/xxx/logging-queue-handler-bug.py", line 33, in <module>
main(mp.Manager().Queue())
File "/home/xxx/logging-queue-handler-bug.py", line 29, in main
logging.config.dictConfig(config)
File "/usr/lib/python3.12/logging/config.py", line 914, in dictConfig
dictConfigClass(config).configure()
File "/usr/lib/python3.12/logging/config.py", line 588, in configure
raise ValueError('Unable to configure handler '
ValueError: Unable to configure handler 'sink'
Queue classes to check for logging QueueHandler
- queue.Queue(),
<queue.Queue at 0x7fb86eeef170>, works. - multiprocessing
- multiprocessing.Queue(),
<multiprocessing.queues.Queue at 0x7fb871790500>, works. - multiprocessing.Manager().Queue()
<AutoProxy[Queue] object, typeid 'Queue' at 0x7fb86ef4a840>, broken.
Its class ismultiprocessing.managers.AutoProxy[Queue], a subclass ofmultiprocessing.managers.BaseProxy.
- multiprocessing.Queue(),
- asyncio.queues.Queue()
<Queue at 0x7fb86f0be4e0 maxsize=0>, broken. - any other Queue?
discuss: how to fix
Check all Queue classes mentioned above in
Line 792 in bd0d97c
| if not isinstance(qspec, (queue.Queue, MPQueue)): |
or just focus on handling special cases: str and dict, while leaving other cases un-checked (e.g., queue.Queue, multiprocessing.queues.Queue).
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
- gh-119819: Fix regression to allow logging configuration with multipr… #120030
- [3.12] gh-119819: Fix regression to allow logging configuration with multipr… (GH-120030) #120034
- [3.13] gh-119819: Fix regression to allow logging configuration with multipr… (GH-120030) #120035
- gh-119819: Update test to skip if _multiprocessing is unavailable. #120067
- [3.12] gh-119819: Update test to skip if _multiprocessing is unavailable. (GH-120067) #120071
- [3.13] gh-119819: Update test to skip if _multiprocessing is unavailable. (GH-120067) #120072
- gh-119819: Update logging configuration to support joinable multiproc… #120090
- [3.12] gh-119819: Update logging configuration to support joinable multiproc… (GH-120090) #120092
- [3.13] gh-119819: Update logging configuration to support joinable multiproc… (GH-120090) #120093
- gh-119819: Conditional skip of logging tests that require multiprocessing subprocess support #120476
- [3.13] gh-119819: Conditional skip of logging tests that require multiprocessing subprocess support (GH-120476) #120531
- [3.12] gh-119819: Conditional skip of logging tests that require multiprocessing subprocess support (GH-120476) #120532
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
picnixz commentedon Jun 2, 2024
My 2 cents: one concrete use case I can imagine is when you want to pass that queue to a pool without using a global variable and a custom initializer. AFAIK, you need a manager-based queue since
multiprocessing.Queuecannot be pickled. There are other (possibly rare) issues mentioned at the end of the https://docs.python.org/3.10/library/multiprocessing.html#pipes-and-queues paragraph, so maybe some people might be affected?When I suggested the protocol-based approach, it was mostly to deal with the issue arising from the proxy interface because checking the runtime type would not help in that case.
shmilee commentedon Jun 3, 2024
Except for the mentioned reasons, 1) some people may get errors when updating to py3.12 due to their previous code using proxy queue, 2) py3.12 excludes but doesn't completely exclude proxy queue (dict qspec), I don't have any other new reasons.
Yes, that's true and makes checking the type of proxy indeed tricky.
If it really needs to be checked, I think picnixz's suggestion is quite good.
(PS: In my personal code, I might directly use its
__class__to check the class, because, for personal projects, I treat the class names in the standard library basically unchanged. Of course, in a standard library this will be weird.)If the final decision is not to check proxy, perhaps the documentation should explicitly mention it.
Because even though its class name is
<class 'multiprocessing.managers.AutoProxy[Queue]'>, it still is a<queue.Queue object at xxx>. Perhaps, besides me, someone also believesthey are the sameAutoProxy[Queue]can be treated asqueue.Queue.cpython/Lib/multiprocessing/managers.py
Lines 1224 to 1225 in 367adc9
pythongh-119819: Fix regression to allow logging configuration with m…
vsajip commentedon Jun 4, 2024
Please check if the changes in the linked PR #120030 fix the problem reported..
gh-119819: Fix regression to allow logging configuration with multipr… (
pythongh-119819: Fix regression to allow logging configuration with m…
pythongh-119819: Fix regression to allow logging configuration with m…
[3.12] gh-119819: Fix regression to allow logging configuration with …
[3.13] gh-119819: Fix regression to allow logging configuration with …
pythongh-119819: Update test to skip if _multiprocessing is unavailable.
gh-119819: Update test to skip if _multiprocessing is unavailable. (G…
pythongh-119819: Update test to skip if _multiprocessing is unavailab…
pythongh-119819: Update test to skip if _multiprocessing is unavailab…
[3.12] gh-119819: Update test to skip if _multiprocessing is unavaila…
[3.13] gh-119819: Update test to skip if _multiprocessing is unavaila…
shmilee commentedon Jun 5, 2024
I just checked. The PR fixes the problem. Thanks!
Output:
shmilee commentedon Jun 5, 2024
Before closing the issue, I will paste a potential error that may never happen. Not sure if anyone has used
JoinableQueueandloggingtogether, so only paste it here and let someone who is searchingJoinableQueueissue confirm their problem.shmilee commentedon Jun 5, 2024
Thank you again! @vsajip @picnixz
pythongh-119819: Update logging configuration to support joinable mul…
gh-119819: Update logging configuration to support joinable multiproc… (
pythongh-119819: Update logging configuration to support joinable mul…
pythongh-119819: Update logging configuration to support joinable mul…
[3.12] gh-119819: Update logging configuration to support joinable mu…
[3.13] gh-119819: Update logging configuration to support joinable mu…
pythongh-119819: Fix regression to allow logging configuration with m…
pythongh-119819: Update test to skip if _multiprocessing is unavailab…
pythongh-119819: Update logging configuration to support joinable mul…
gh-119819: Conditional skip of logging tests that require multiproces…
pythongh-119819: Conditional skip of logging tests that require multi…
pythongh-119819: Conditional skip of logging tests that require multi…
[3.13] gh-119819: Conditional skip of logging tests that require mult…
[3.12] gh-119819: Conditional skip of logging tests that require mult…
pythongh-119819: Conditional skip of logging tests that require multi…
noreentry commentedon Jul 13, 2024
multiprocessing.Pool with spawn method breaks logging.handlers.QueueHandler configuration
got exception (when q = manager.Queue() or q = multiprocessing.Queue())
vsajip commentedon Jul 13, 2024
Not sure this is the same error - what exact version of 3.12 is in use? What happens with 3.13?
noreentry commentedon Jul 13, 2024
it works on 3.12.3
doesn't work on 3.12.4
can't test it on 3.13
pythongh-119819: Fix regression to allow logging configuration with m…
pythongh-119819: Update test to skip if _multiprocessing is unavailab…
pythongh-119819: Update logging configuration to support joinable mul…
pythongh-119819: Conditional skip of logging tests that require multi…
[3.12] pythongh-119819: Conditional skip of logging tests that requir…