Debian Codegraph @

docs/source/Tutorials/bankprograms/bank22.py

raw symbols SCIP
1 """ bank22: An interruption by a phone call """
2 from SimPy.Simulation import *
3
4 ## Model components ------------------------
5
6
7 class Customer(Process):
8 """ Customer arrives, looks around and leaves """
9
10 def visit(self, timeInBank, onphone):
11 print("%7.4f %s: Here I am" % (now(), self.name))
12 yield hold, self, timeInBank
13 if self.interrupted():
14 timeleft = self.interruptLeft
15 self.interruptReset()
16 print("%7.4f %s: Excuse me" % (now(), self.name))
17 print("%7.4f %s: Hello! I'll call back" % (now(), self.name))
18 yield hold, self, onphone
19 print("%7.4f %s: Sorry, where were we?" % (now(), self.name))
20 yield hold, self, timeleft
21 print("%7.4f %s: I must leave" % (now(), self.name))
22
23
24 class Call(Process):
25 """ Cellphone call arrives and interrupts """
26
27 def ring(self, klaus, timeOfCall):
28 yield hold, self, timeOfCall
29 print("%7.4f Ringgg!" % (now()))
30 self.interrupt(klaus)
31
32 ## Experiment data -------------------------
33
34 timeInBank = 20.0
35 timeOfCall = 9.0
36 onphone = 3.0
37 maxTime = 100.0
38
39
40 ## Model/Experiment ----------------------------------
41
42 initialize()
43 klaus = Customer(name="Klaus")
44 activate(klaus, klaus.visit(timeInBank, onphone))
45 call = Call(name="klaus")
46 activate(call, call.ring(klaus, timeOfCall))
47 simulate(until=maxTime)