def calling(self): while True: signal1.signal("wake up!") print "%s: signal 1 has occurred" % now() yield hold, self, 10 signal2.signal("and again") signal2.signal("sig 2 again") print "%s: signal1, signal2 have occurred" % now() yield hold, self, 10
def startCollection(self, when=0.0, monitors=None, tallies=None): """Starts data collection of all designated Monitor and Tally objects (default = all) at time 'when'. """ class Starter(Process): def collect(self, monitors, tallies): for m in monitors: m.reset() for t in tallies: t.reset() yield hold, self if monitors is None: monitors = self.allMonitors if tallies is None: tallies = self.allTallies if when == 0.0: for m in monitors: try: ylast = m[-1][1] empty = False except IndexError: empty = True m.reset() if not empty: m.observe(t=now(), y=ylast) for t in tallies: t.reset() else: s = Starter(sim=self) self.activate(s, s.collect(monitors=monitors, tallies=tallies), at=when, prior=True)
def startCollection(self, when=0.0, monitors=None, tallies=None): """Starts data collection of all designated Monitor and Tally objects (default = all) at time 'when'. """ class Starter(Process): def collect(self, monitors, tallies): for m in monitors: m.reset() for t in tallies: t.reset() yield hold, self if monitors is None: monitors = self.allMonitors if tallies is None: tallies = self.allTallies if when == 0.0: for m in monitors: try: ylast = m[-1][1] empty = False except IndexError: empty = True m.reset() if not empty: m.observe(t=now(), y=ylast) for t in tallies: t.reset() else: s = Starter(sim=self) self.activate(s, s.collect(monitors = monitors, tallies = tallies),\ at = when, prior = True)
def waiting(self, theSignal): while True: yield waitevent, self, theSignal print "%s: process '%s' continued after waiting for %s" % ( self.sim.now(), self.name, theSignal.name, ) yield queueevent, self, theSignal print "%s: process '%s' continued after queueing for %s" % (now(), self.name, theSignal.name)
def testTimeout2(): """Test that timeout occurs when resource has no capacity free """ s = Simulation() s.initialize() res = Resource(name="Server", capacity=0, sim=s) usetime = 5 timeout = 3 j1 = JobTO(server=res, name="Job_1", sim=s) s.activate(j1, j1.execute(timeout=timeout, usetime=usetime)) j2 = JobTO(server=res, name="Job_2", sim=s) s.activate(j2, j2.execute(timeout=timeout, usetime=usetime)) s.simulate(until=2 * usetime) assert s.now() == timeout, "time %s not == timeout" % now() assert not j1.gotResource, "Job_1 got resource" assert not j2.gotResource, "Job_2 got resource" assert not (res.waitQ or res.activeQ), "job waiting or using resource"
def operate(self, repairduration=0): print self.sim.now(), ">> %s starts" % (self.name) tripleft = 1000 while tripleft > 0: yield hold, self, tripleft if self.interrupted(): print "interrupted by %s" % self.interruptCause.name print "%s: %s breaks down " % (now(), self.name) tripleft = self.interruptLeft self.interruptReset() print "tripleft ", tripleft s.reactivate(br, delay=repairduration) # breakdowns only during operation yield hold, self, repairduration print self.sim.now(), " repaired" else: break # no breakdown, ergo bus arrived print self.sim.now(), "<< %s done" % (self.name)
def visit(self,timeInBank): print now(),self.name," Here I am" yield hold,self,timeInBank print now(),self.name," I must leave"