<s> """<STR_LIT>""" <EOL> from twisted . python import hook <EOL> class DummyLock ( object ) : <EOL> """<STR_LIT>""" <EOL> def __reduce__ ( self ) : <EOL> return ( unpickle_lock , ( ) ) <EOL> def unpickle_lock ( ) : <EOL> if threadingmodule is not None : <EOL> return XLock ( ) <EOL> else : <EOL> return DummyLock ( ) <EOL> unpickle_lock . __safe_for_unpickling__ = True <EOL> def _synchPre ( self , * a , ** b ) : <EOL> if '<STR_LIT>' not in self . __dict__ : <EOL> _synchLockCreator . acquire ( ) <EOL> if '<STR_LIT>' not in self . __dict__ : <EOL> self . __dict__ [ '<STR_LIT>' ] = XLock ( ) <EOL> _synchLockCreator . release ( ) <EOL> self . _threadable_lock . acquire ( ) <EOL> def _synchPost ( self , * a , ** b ) : <EOL> self . _threadable_lock . release ( ) <EOL> def synchronize ( * klasses ) : <EOL> """<STR_LIT>""" <EOL> if threadmodule is not None : <EOL> for klass in klasses : <EOL> for methodName in klass . synchronized : <EOL> hook . addPre ( klass , methodName , _synchPre ) <EOL> hook . addPost ( klass , methodName , _synchPost ) <EOL> def init ( with_threads = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> global threaded , _synchLockCreator , XLock <EOL> if with_threads : <EOL> if not threaded : <EOL> if threadmodule is not None : <EOL> threaded = True <EOL> class XLock ( threadingmodule . _RLock , object ) : <EOL> def __reduce__ ( self ) : <EOL> return ( unpickle_lock , ( ) ) <EOL> _synchLockCreator = XLock ( ) <EOL> else : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> else : <EOL> if threaded : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> else : <EOL> pass <EOL> _dummyID = object ( ) <EOL> def getThreadID ( ) : <EOL> if threadmodule is None : <EOL> return _dummyID <EOL> return threadmodule . get_ident ( ) <EOL> def isInIOThread ( ) : <EOL> """<STR_LIT>""" <EOL> return ioThread == getThreadID ( ) <EOL> def registerAsIOThread ( ) : <EOL> """<STR_LIT>""" <EOL> global ioThread <EOL> ioThread = getThreadID ( ) <EOL> ioThread = None <EOL> threaded = False <EOL> try : <EOL> import thread as threadmodule <EOL> import threading as threadingmodule <EOL> except ImportError : <EOL> threadmodule = None <EOL> threadingmodule = None <EOL> else : <EOL> init ( True ) <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] </s>
