<s> import sys , os , time , random <EOL> import smisk . ipc . bsddb <EOL> def main ( ) : <EOL> from optparse import OptionParser <EOL> parser = OptionParser ( ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , <EOL> help = "<STR_LIT>" , <EOL> metavar = "<STR_LIT>" , default = <NUM_LIT:100> , type = '<STR_LIT:int>' ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_option ( "<STR_LIT>" , "<STR_LIT>" , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> ( options , args ) = parser . parse_args ( ) <EOL> if not options . read and not options . write : <EOL> options . read = True <EOL> store = smisk . ipc . bsddb . shared_dict ( ) <EOL> idle_sec = float ( options . idle ) / <NUM_LIT> <EOL> if options . detect_concurrance : <EOL> options . write = True <EOL> options . read = True <EOL> rw = '<STR_LIT>' <EOL> if options . read and options . write : <EOL> rw = '<STR_LIT>' <EOL> elif options . read : <EOL> rw = '<STR_LIT>' <EOL> pid = os . getpid ( ) <EOL> idle_msg = '<STR_LIT>' <EOL> if idle_sec > <NUM_LIT:0.0> : <EOL> idle_msg = '<STR_LIT>' % ( idle_sec * <NUM_LIT> ) <EOL> print '<STR_LIT>' % ( pid , rw , idle_msg ) <EOL> while <NUM_LIT:1> : <EOL> if options . write : <EOL> time . sleep ( random . random ( ) * idle_sec ) <EOL> store [ '<STR_LIT>' ] = pid <EOL> if options . read : <EOL> time . sleep ( random . random ( ) * idle_sec ) <EOL> try : <EOL> pid_found = store [ '<STR_LIT>' ] <EOL> except KeyError : <EOL> pass <EOL> if options . detect_concurrance and pid_found != pid : <EOL> print '<STR_LIT>' % ( pid , pid_found ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
