| 1 | from SimPy.Simulation import Process, activate, initialize, hold, now, simulate |
| 2 | |
| 3 | |
| 4 | class Firework(Process): |
| 5 | |
| 6 | def execute(self): |
| 7 | print('%s firework launched' % now()) |
| 8 | yield hold, self, 10.0 # wait 10.0 time units |
| 9 | for i in range(10): |
| 10 | yield hold, self, 1.0 |
| 11 | print('%s tick' % now()) |
| 12 | yield hold, self, 10.0 # wait another 10.0 time units |
| 13 | print('%s Boom!!' % now()) |
| 14 | |
| 15 | |
| 16 | initialize() |
| 17 | f = Firework() # create a Firework object, and |
| 18 | # activate it (with some default parameters) |
| 19 | activate(f, f.execute(), at=0.0) |
| 20 | simulate(until=100) |