<s> __author__ = '<STR_LIT>' <EOL> from barrier import Barrier <EOL> class StabilizedBuffer ( object ) : <EOL> def __init__ ( self , duration = <NUM_LIT:0> , distance = None ) : <EOL> object . __init__ ( self ) <EOL> self . duration = duration <EOL> self . curr_val = None <EOL> self . barrier = Barrier ( ) <EOL> self . distance = distance <EOL> self . schmitt_low = None <EOL> self . schmitt_high = None <EOL> def set_limits ( self ) : <EOL> self . schmitt_low = self . curr_val - ( self . distance / <NUM_LIT> ) <EOL> self . schmitt_high = self . curr_val + ( self . distance / <NUM_LIT> ) <EOL> def put ( self , value ) : <EOL> self . curr_val = value <EOL> if self . distance is not None : <EOL> if self . schmitt_low is None : <EOL> self . set_limits ( ) <EOL> if self . schmitt_low < self . curr_val < self . schmitt_high : <EOL> pass <EOL> else : <EOL> self . set_limits ( ) <EOL> self . barrier . go ( ) <EOL> else : <EOL> self . barrier . go ( ) <EOL> def get ( self ) : <EOL> while True : <EOL> success = self . barrier . wait ( self . duration ) <EOL> if not success : <EOL> return self . curr_val <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from gevent_actor import * <EOL> from gevent import sleep <EOL> class Test ( Actor ) : <EOL> def prepare ( self ) : <EOL> self . test_buff = StabilizedBuffer ( <NUM_LIT:5> ) <EOL> self . test_buff2 = StabilizedBuffer ( <NUM_LIT:5> ) <EOL> def action ( self ) : <EOL> while True : <EOL> x = self . test_buff . get ( ) <EOL> print "<STR_LIT>" , x <EOL> def action_4 ( self ) : <EOL> while True : <EOL> x = self . test_buff2 . get ( ) <EOL> print "<STR_LIT>" , x <EOL> def action_2 ( self ) : <EOL> i = <NUM_LIT:0> <EOL> while True : <EOL> print "<STR_LIT>" , i <EOL> self . test_buff . put ( i ) <EOL> i += <NUM_LIT:1> <EOL> sleep ( <NUM_LIT:2> ) <EOL> def action_3 ( self ) : <EOL> i = <NUM_LIT:100> <EOL> while True : <EOL> print "<STR_LIT>" , i <EOL> self . test_buff2 . put ( i ) <EOL> i += <NUM_LIT:100> <EOL> sleep ( <NUM_LIT:6> ) <EOL> print "<STR_LIT>" <EOL> Test ( ) <EOL> wait_all ( ) </s>
