@@ -90,7 +90,8 @@ def __repr__(self):
9090 return "<MaybeEncodingError: %s>" % str (self )
9191
9292
93- def worker (inqueue , outqueue , initializer = None , initargs = (), maxtasks = None ):
93+ def worker (inqueue , outqueue , initializer = None , initargs = (), maxtasks = None ,
94+ wrap_exception = False ):
9495 assert maxtasks is None or (type (maxtasks ) == int and maxtasks > 0 )
9596 put = outqueue .put
9697 get = inqueue .get
@@ -117,7 +118,8 @@ def worker(inqueue, outqueue, initializer=None, initargs=(), maxtasks=None):
117118 try :
118119 result = (True , func (* args , ** kwds ))
119120 except Exception as e :
120- e = ExceptionWithTraceback (e , e .__traceback__ )
121+ if wrap_exception :
122+ e = ExceptionWithTraceback (e , e .__traceback__ )
121123 result = (False , e )
122124 try :
123125 put ((job , i , result ))
@@ -137,6 +139,8 @@ class Pool(object):
137139 '''
138140 Class which supports an async version of applying functions to arguments.
139141 '''
142+ _wrap_exception = True
143+
140144 def Process (self , * args , ** kwds ):
141145 return self ._ctx .Process (* args , ** kwds )
142146
@@ -220,7 +224,8 @@ def _repopulate_pool(self):
220224 w = self .Process (target = worker ,
221225 args = (self ._inqueue , self ._outqueue ,
222226 self ._initializer ,
223- self ._initargs , self ._maxtasksperchild )
227+ self ._initargs , self ._maxtasksperchild ,
228+ self ._wrap_exception )
224229 )
225230 self ._pool .append (w )
226231 w .name = w .name .replace ('Process' , 'PoolWorker' )
@@ -736,6 +741,7 @@ def _set(self, i, obj):
736741#
737742
738743class ThreadPool (Pool ):
744+ _wrap_exception = False
739745
740746 @staticmethod
741747 def Process (* args , ** kwds ):
0 commit comments