<s> from sysv_ipc import * <EOL> import Config <EOL> class SemLock : <EOL> sems = None <EOL> @ staticmethod <EOL> def Init ( ) : <EOL> semkey = Config . Config . GetInt ( "<STR_LIT>" , <NUM_LIT> ) <EOL> try : <EOL> SemLock . sems = [ Semaphore ( semkey ) ] <EOL> except ExistentialError : <EOL> SemLock . sems = [ Semaphore ( semkey , flags = IPC_CREAT | IPC_EXCL , mode = <NUM_LIT:0> <NUM_LIT> ) ] ; <EOL> for i in range ( len ( sems ) ) : <EOL> SemLock . sems [ i ] . release ( ) <EOL> @ staticmethod <EOL> def Lock ( lockid , timeout = None ) : <EOL> if ( SemLock . sems == None ) : <EOL> SemLock . Init ( ) <EOL> if ( lockid != <NUM_LIT:0> ) : <EOL> Log . error ( "<STR_LIT>" ) <EOL> lockid = <NUM_LIT:0> <EOL> SemLock . sems [ lockid ] . acquire ( timeout ) <EOL> @ staticmethod <EOL> def Unlock ( lockid ) : <EOL> if ( SemLock . sems == None ) : <EOL> SemLock . Init ( ) <EOL> if ( lockid != <NUM_LIT:0> ) : <EOL> Log . error ( "<STR_LIT>" ) <EOL> lockid = <NUM_LIT:0> <EOL> SemLock . sems [ lockid ] . release ( ) </s>
