<s> from . . core import Machine , Transition , Event <EOL> from threading import RLock <EOL> import inspect <EOL> class LockedMethod : <EOL> def __init__ ( self , lock , func ) : <EOL> self . lock = lock <EOL> self . func = func <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> with self . lock : <EOL> return self . func ( * args , ** kwargs ) <EOL> class LockedEvent ( Event ) : <EOL> def trigger ( self , * args , ** kwargs ) : <EOL> with self . machine . rlock : <EOL> super ( LockedEvent , self ) . trigger ( * args , ** kwargs ) <EOL> class LockedMachine ( Machine ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . rlock = RLock ( ) <EOL> super ( LockedMachine , self ) . __init__ ( * args , ** kwargs ) <EOL> def __getattribute__ ( self , item ) : <EOL> f = super ( LockedMachine , self ) . __getattribute__ <EOL> tmp = f ( item ) <EOL> if inspect . ismethod ( tmp ) and item not in "<STR_LIT>" : <EOL> return LockedMethod ( f ( '<STR_LIT>' ) , tmp ) <EOL> return tmp <EOL> def __getattr__ ( self , item ) : <EOL> try : <EOL> return super ( LockedMachine , self ) . __getattribute__ ( item ) <EOL> except AttributeError : <EOL> return super ( LockedMachine , self ) . __getattr__ ( item ) <EOL> @ staticmethod <EOL> def _create_event ( * args , ** kwargs ) : <EOL> return LockedEvent ( * args , ** kwargs ) </s>
