<s> """<STR_LIT>""" <EOL> try : <EOL> from queue import Queue <EOL> except : <EOL> from Queue import Queue <EOL> import threading <EOL> import traceback <EOL> class Worker : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . q = Queue ( ) <EOL> self . running = False <EOL> def start ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . running : <EOL> self . running = True <EOL> threading . Thread ( target = self . loop ) . start ( ) <EOL> def stop ( self ) : <EOL> """<STR_LIT>""" <EOL> self . running = False <EOL> self . q . put ( lambda : <NUM_LIT> ) <EOL> def execute ( self , callback ) : <EOL> """<STR_LIT>""" <EOL> self . q . put ( callback ) <EOL> def loop ( self ) : <EOL> """<STR_LIT>""" <EOL> while self . running : <EOL> try : <EOL> callback = self . q . get ( block = True ) <EOL> callback ( ) <EOL> except : <EOL> print ( "<STR_LIT>" , traceback . format_exc ( ) ) <EOL> __worker = None <EOL> def execute ( callback ) : <EOL> """<STR_LIT>""" <EOL> global __worker <EOL> if not __worker : <EOL> __worker = Worker ( ) <EOL> __worker . start ( ) <EOL> __worker . execute ( callback ) <EOL> def unload_handler ( ) : <EOL> """<STR_LIT>""" <EOL> global __worker <EOL> if __worker : <EOL> __worker . stop ( ) <EOL> __worker = None </s>
