def whisper(self, what): self._heard = self.mangle( what ) time.sleep(1) # print str(self)+" heard "+str(self._heard) if self._next: dramatis.release( self._next ).whisper( self._heard ) self.actor.accept( "ask" )
def test_short_release(self): "should have a nice short method for casts" class O (object): def foo(self,arg): assert arg == "bar" name = dramatis.Actor( O() ) dramatis.release( name ).foo( "bar" )
def pingpong(self,count,partner): if count == 0: print "%s: done" % self._name else: if count % 500 == 0 or count % 500 == 1: print "%s: pingpong %d" % ( self._name, count ) dramatis.release( partner ).pingpong( count-1, self ) time.sleep( 0.001 )
def offer(self, bid, bidder): if bid >= self._max_bid + self._bid_increment: if self._max_bid >= self._min_bid: dramatis.release( self._max_bidder ).beaten_offer( bid ) self._max_bid = bid self._max_bidder = bidder return [ "best_offer", None ] else: return [ "beaten_offer", self._max_bid ]
def f(self): self._a = 1 assert self._a == 1 dramatis.release( self.actor.name ).g() time.sleep( 1 ) assert self._a == 1 self.actor.actor_yield() assert self._a == 2 return self._a
def __init__(self, name, increment, top, auction): self._name = name self._increment = increment self._top = top self._auction = auction self._current = 0 self.log( "started" ) self._max = auction.inquire()[0] self.log( "status " + str(self._max) ) dramatis.release( self.actor.name ).bid()
def __init__(self, seller, min_bid, closing): self._seller = seller self._min_bid = min_bid self._closing = closing self._bid_increment = 10 self._max_bid = self._min_bid - self._bid_increment self._max_bidder = None self.actor.refuse( "winner" ) dramatis.release( self.actor.name ).close()
def test_main_caller(self): "should do something reasonable when the caller is main" callee = dramatis.Actor(object()) okay = False try: callee.callee() raise Exception("should not be reached") except AttributeError: okay = True assert okay dramatis.release(callee).callee() dramatis.Runtime.current.warnings = False okay = False try: dramatis.Runtime.current.quiesce() except dramatis.error.Uncaught: okay = True assert okay dramatis.Runtime.current.warnings = True assert len(dramatis.Runtime.current.exceptions()) == 1 dramatis.Runtime.current.clear_exceptions()
def close(self): self.actor.actor_yield( self._closing - time.time() ) if self._max_bid > self._min_bid: dramatis.release( self._seller ).winner( self._max_bidder ) dramatis.release( self._max_bidder ).winner( self._seller ) self.actor.become( Auction.Over( self._max_bidder, self._max_bid ) ) else: dramatis.release( self._seller ).failed( self._max_bid ) self.actor.become( Auction.Over( None, self._max_bid ) )
def __init__(self,times,pong): self.pings_left = times dramatis.release( pong ).ping( self )
def continuation_exception(self, exception): if self._exception_block: self._exception_block( exception ) else: dramatis.release( self._name ).dramatis_exception( exception ) return False
def caller(self, callee): dramatis.release(callee).callee()
def beaten_offer(self, max_bid): self.log("beaten offer: " + str(max_bid)) self._max = max_bid dramatis.release( self.actor.name ).bid()
def exception( self, exception ): try: dramatis.interface( dramatis.release( self._name ) ).exception( exception ) except Exception, e: print_exc() raise e
def ping(self,caller): if self.pong_count % 1000 == 0: print "Pong: ping", self.pong_count self.pong_count += 1 dramatis.release( caller ).pong( self )
def pong(self,caller): if self.pings_left % 1000 == 0: print "Ping: pong" if self.pings_left > 0: self.pings_left -= 1 dramatis.release( caller ).ping( self )
def __init__( self ): self.actor.always( "wx", True ) self._wx = Screen.Server.App() ( dramatis.release( self._wx ) ).run()
def __init__(self, n, level = None ): super(Fib,self).__init__(self) if level == None: level = THREAD_LEVELS self.actor.refuse("value") dramatis.release( self.actor.name ).calc( n, level )