Debian Codegraph @

docs/source/Manuals/programs/storewidget.py

raw symbols SCIP
1 from SimPy.Simulation import (Lister, Process, Store, activate, get, hold,
2 initialize, now, put, simulate)
3
4
5 class ProducerD(Process):
6 def __init__(self):
7 Process.__init__(self)
8
9 def produce(self): # the ProducerD PEM
10 while True:
11 yield put, self, buf, [Widget(9), Widget(7)]
12 yield hold, self, 10
13
14
15 class ConsumerD(Process):
16 def __init__(self):
17 Process.__init__(self)
18
19 def consume(self): # the ConsumerD PEM
20 while True:
21 toGet = 3
22 yield get, self, buf, toGet
23 assert len(self.got) == toGet
24 print('%s Get widget weights %s' % (now(),
25 [x.weight for x in self.got]))
26 yield hold, self, 11
27
28
29 class Widget(Lister):
30 def __init__(self, weight=0):
31 self.weight = weight
32
33
34 widgbuf = []
35 for i in range(10):
36 widgbuf.append(Widget(5))
37
38 initialize()
39
40 buf = Store(capacity=11, initialBuffered=widgbuf, monitored=True)
41
42 for i in range(3): # define and activate 3 producer objects
43 p = ProducerD()
44 activate(p, p.produce())
45
46 for i in range(3): # define and activate 3 consumer objects
47 c = ConsumerD()
48 activate(c, c.consume())
49
50 simulate(until=50)
51
52 print('LenBuffer: %s' % buf.bufferMon) # length of buffer
53 print('getQ: %s' % buf.getQMon) # length of getQ
54 print('putQ %s' % buf.putQMon) # length of putQ