#NEWLINE# def worker( inqueue , outqueue , initializer = None , initargs = ( ) , maxtasks = None ) : #NEWLINE# #INDENT# assert ( ( maxtasks is None ) or ( ( type ( maxtasks ) == int ) and ( maxtasks > 0 ) ) ) #NEWLINE# put = outqueue . put #NEWLINE# get = inqueue . get #NEWLINE# if hasattr ( inqueue , '_writer' ) : #NEWLINE# #INDENT# inqueue . _writer . close ( ) #NEWLINE# outqueue . _reader . close ( ) #NEWLINE# #UNINDENT# if ( initializer is not None ) : #NEWLINE# #INDENT# initializer ( * initargs ) #NEWLINE# #UNINDENT# completed = 0 #NEWLINE# while ( ( maxtasks is None ) or ( maxtasks and ( completed < maxtasks ) ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# task = get ( ) #NEWLINE# #UNINDENT# except ( EOFError , IOError ) : #NEWLINE# #INDENT# debug ( 'worker got EOFError or IOError -- exiting' ) #NEWLINE# break #NEWLINE# #UNINDENT# if ( task is None ) : #NEWLINE# #INDENT# debug ( 'worker got sentinel -- exiting' ) #NEWLINE# break #NEWLINE# #UNINDENT# ( job , i , func , args , kwds ) = task #NEWLINE# try : #NEWLINE# #INDENT# result = ( True , func ( * args , ** kwds ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# result = ( False , e ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# put ( ( job , i , result ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# wrapped = MaybeEncodingError ( e , result [ 1 ] ) #NEWLINE# debug ( ( 'Possible encoding error while sending result: %s' % wrapped ) ) #NEWLINE# put ( ( get , i , ( False , wrapped ) ) ) #NEWLINE# #UNINDENT# completed += 1 #NEWLINE# #UNINDENT# debug ( ( 'worker exiting after %d tasks' % completed ) )