<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import <EOL> from functools import wraps <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 ) : <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 ) : <EOL> self . _threadable_lock . release ( ) <EOL> def _sync ( klass , function ) : <EOL> @ wraps ( function ) <EOL> def sync ( self , * args , ** kwargs ) : <EOL> _synchPre ( self ) <EOL> try : <EOL> return function ( self , * args , ** kwargs ) <EOL> finally : <EOL> _synchPost ( self ) <EOL> return sync <EOL> def synchronize ( * klasses ) : <EOL> """<STR_LIT>""" <EOL> if threadingmodule is not None : <EOL> for klass in klasses : <EOL> for methodName in klass . synchronized : <EOL> sync = _sync ( klass , klass . __dict__ [ methodName ] ) <EOL> setattr ( klass , methodName , sync ) <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 threadingmodule 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 threadingmodule is None : <EOL> return _dummyID <EOL> return threadingmodule . currentThread ( ) . 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 threading as threadingmodule <EOL> except ImportError : <EOL> threadingmodule = None <EOL> else : <EOL> init ( True ) <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] </s>
