@@ -3952,14 +3952,23 @@ def test_config_queue_handler(self):
3952
3952
msg = str (ctx .exception )
3953
3953
self .assertEqual (msg , "Unable to configure handler 'ah'" )
3954
3954
3955
+ def _apply_simple_queue_listener_configuration (self , qspec ):
3956
+ self .apply_config ({
3957
+ "version" : 1 ,
3958
+ "handlers" : {
3959
+ "queue_listener" : {
3960
+ "class" : "logging.handlers.QueueHandler" ,
3961
+ "queue" : qspec ,
3962
+ },
3963
+ },
3964
+ })
3965
+
3955
3966
@threading_helper .requires_working_threading ()
3956
3967
@support .requires_subprocess ()
3957
3968
@patch ("multiprocessing.Manager" )
3958
3969
def test_config_queue_handler_does_not_create_multiprocessing_manager (self , manager ):
3959
3970
# gh-120868, gh-121723, gh-124653
3960
3971
3961
- import multiprocessing
3962
-
3963
3972
for qspec in [
3964
3973
{"()" : "queue.Queue" , "maxsize" : - 1 },
3965
3974
queue .Queue (),
@@ -3972,52 +3981,41 @@ def test_config_queue_handler_does_not_create_multiprocessing_manager(self, mana
3972
3981
# check that the queue object correctly implements the API.
3973
3982
CustomQueueFakeProtocol (),
3974
3983
MinimalQueueProtocol (),
3975
- # multiprocessing.Queue() is a valid queue for the logging module
3976
- # but multiprocessing.SimpleQueue() is NOT valid because it lacks
3977
- # the 'put_nowait' method needed by the logging queue handler.
3978
- multiprocessing .Queue (),
3979
3984
]:
3980
3985
with self .subTest (qspec = qspec ):
3981
- self .apply_config (
3982
- {
3983
- "version" : 1 ,
3984
- "handlers" : {
3985
- "queue_listener" : {
3986
- "class" : "logging.handlers.QueueHandler" ,
3987
- "queue" : qspec ,
3988
- },
3989
- },
3990
- }
3991
- )
3986
+ self ._apply_simple_queue_listener_configuration (qspec )
3992
3987
manager .assert_not_called ()
3993
3988
3994
3989
@patch ("multiprocessing.Manager" )
3995
3990
def test_config_queue_handler_invalid_config_does_not_create_multiprocessing_manager (self , manager ):
3996
3991
# gh-120868, gh-121723, gh-124653
3997
3992
3993
+ for qspec in [object (), CustomQueueWrongProtocol ()]:
3994
+ with self .subTest (qspec = qspec ), self .assertRaises (ValueError ):
3995
+ self ._apply_simple_queue_listener_configuration (qspec )
3996
+ manager .assert_not_called ()
3997
+
3998
+ @skip_if_tsan_fork
3999
+ @support .requires_subprocess ()
4000
+ @unittest .skipUnless (support .Py_DEBUG , "requires a debug build for testing"
4001
+ " assertions in multiprocessing" )
4002
+ def test_config_reject_simple_queue_handler_multiprocessing_context (self ):
4003
+ # multiprocessing.SimpleQueue does not implement 'put_nowait'
4004
+ # and thus cannot be used as a queue-like object (gh-124653)
4005
+
3998
4006
import multiprocessing
3999
4007
4000
- for qspec in [
4001
- object (),
4002
- CustomQueueWrongProtocol (),
4003
- # multiprocessing.SimpleQueue does not implement the 'put_nowait'
4004
- # method and thus cannot be used as a queue-like object here.
4005
- multiprocessing .SimpleQueue (),
4006
- ]:
4007
- with self .subTest (qspec = qspec ):
4008
+ if support .MS_WINDOWS :
4009
+ start_methods = ['spawn' ]
4010
+ else :
4011
+ start_methods = ['spawn' , 'fork' , 'forkserver' ]
4012
+
4013
+ for start_method in start_methods :
4014
+ with self .subTest (start_method = start_method ):
4015
+ ctx = multiprocessing .get_context (start_method )
4016
+ qspec = ctx .SimpleQueue ()
4008
4017
with self .assertRaises (ValueError ):
4009
- self .apply_config (
4010
- {
4011
- "version" : 1 ,
4012
- "handlers" : {
4013
- "queue_listener" : {
4014
- "class" : "logging.handlers.QueueHandler" ,
4015
- "queue" : qspec ,
4016
- },
4017
- },
4018
- }
4019
- )
4020
- manager .assert_not_called ()
4018
+ self ._apply_simple_queue_listener_configuration (qspec )
4021
4019
4022
4020
@skip_if_tsan_fork
4023
4021
@support .requires_subprocess ()
0 commit comments