@@ -780,25 +780,44 @@ def configure_handler(self, config):
780
780
# if 'handlers' not in config:
781
781
# raise ValueError('No handlers specified for a QueueHandler')
782
782
if 'queue' in config :
783
- from multiprocessing .queues import Queue as MPQueue
784
- from multiprocessing import Manager as MM
785
- proxy_queue = MM ().Queue ()
786
- proxy_joinable_queue = MM ().JoinableQueue ()
787
783
qspec = config ['queue' ]
788
- if not isinstance (qspec , (queue .Queue , MPQueue ,
789
- type (proxy_queue ), type (proxy_joinable_queue ))):
790
- if isinstance (qspec , str ):
791
- q = self .resolve (qspec )
792
- if not callable (q ):
793
- raise TypeError ('Invalid queue specifier %r' % qspec )
794
- q = q ()
795
- elif isinstance (qspec , dict ):
796
- if '()' not in qspec :
797
- raise TypeError ('Invalid queue specifier %r' % qspec )
798
- q = self .configure_custom (dict (qspec ))
799
- else :
784
+
785
+ if isinstance (qspec , str ):
786
+ q = self .resolve (qspec )
787
+ if not callable (q ):
800
788
raise TypeError ('Invalid queue specifier %r' % qspec )
801
- config ['queue' ] = q
789
+ config ['queue' ] = q ()
790
+ elif isinstance (qspec , dict ):
791
+ if '()' not in qspec :
792
+ raise TypeError ('Invalid queue specifier %r' % qspec )
793
+ config ['queue' ] = self .configure_custom (dict (qspec ))
794
+ else :
795
+ from multiprocessing .queues import Queue as MPQueue
796
+
797
+ if not isinstance (qspec , (queue .Queue , MPQueue )):
798
+ # Safely check if 'qspec' is an instance of Manager.Queue
799
+ # / Manager.JoinableQueue
800
+
801
+ from multiprocessing import Manager as MM
802
+ from multiprocessing .managers import BaseProxy
803
+
804
+ # if it's not an instance of BaseProxy, it also can't be
805
+ # an instance of Manager.Queue / Manager.JoinableQueue
806
+ if isinstance (qspec , BaseProxy ):
807
+ # Sometimes manager or queue creation might fail
808
+ # (e.g. see issue gh-120868). In that case, any
809
+ # exception during the creation of these queues will
810
+ # propagate up to the caller and be wrapped in a
811
+ # `ValueError`, whose cause will indicate the details of
812
+ # the failure.
813
+ mm = MM ()
814
+ proxy_queue = mm .Queue ()
815
+ proxy_joinable_queue = mm .JoinableQueue ()
816
+ if not isinstance (qspec , (type (proxy_queue ), type (proxy_joinable_queue ))):
817
+ raise TypeError ('Invalid queue specifier %r' % qspec )
818
+ else :
819
+ raise TypeError ('Invalid queue specifier %r' % qspec )
820
+
802
821
if 'listener' in config :
803
822
lspec = config ['listener' ]
804
823
if isinstance (lspec , type ):
0 commit comments