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