Re: Multiple, Simultaneous Interrupts
kgmuller <kgmuller <at> xs4all.nl>
2008-09-15 08:16:47 GMT
Dan,
in SimPy, processes can only interrupt processes which are
active, i.e. in a 'yield hold'. An interrupt of a process in an interrupted
sttaus is thus not possible.
Here is a modification of your program which shows what is
happening:
import SimPy.SimulationTrace as Sim
class Test(Sim.Process):
def
__init__(self, name):
Sim.Process.__init__(self, name=name)
def
be_interrupted(self):
print self.name, "waiting to be
interrupted..."
yield Sim.hold,
self, 50
while
self.interrupted():
self.interruptReset()
yield Sim.hold, self, self.interruptLeft
def interrupt_other(self,
other):
yield Sim.hold, self,
5
if
other.active():
self.interrupt(other)
print "%s interrupted
%s"%(self.name,other.name)
else:
print "%s not active. %s can't
interrupt."%(other.name,self.name)
Sim.initialize()
t1 = Test('t1')
t2 =
Test('t2')
t3 = Test('t3')
Sim.activate(t1, t1.be_interrupted())
Sim.activate(t2,
t2.interrupt_other(t1))
Sim.activate(t3,
t3.interrupt_other(t1))
Sim.simulate(until=50)
It produces:
0 activate <t1> at time: 0 prior: False
0 activate
<t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior:
False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0
hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate
<t1> time: 5 prior: False
5 interrupt by: <t2> of:
<t1>
t2 interrupted t1
5 <t2> terminated
t1 not active. t3
can't interrupt.
5 <t3> terminated
5 hold <t1> delay: 45
50
<t1> terminated
Klaus Muller
Also, for convenience, here's the output the test code gives.
Note that t1 is only interrupted once, although both t2 and t3
terminate:
0 activate <t1> at time: 0 prior: False
0 activate
<t2> at time: 0 prior: False
0 activate <t3> at time: 0 prior:
False
t1 waiting to be interrupted...
0 hold <t1> delay: 50
0
hold <t2> delay: 5
0 hold <t3> delay: 5
5 reactivate
<t1> time: 5 prior: False
5 interrupt by: <t2> of:
<t1>
5 <t2> terminated
5 <t3> terminated
5 hold
<t1> delay: 45
50 <t1> terminated
- Dan
On Wed, Sep 10, 2008 at 7:08 PM, Dan Homerick
<danhomerick <at> gmail.com>
wrote:
I'm not sure if this is a problem with SimPy code or mine, but
I'm having trouble getting multiple, simultaneous interrupts to both take
effect. Any advice or workarounds?
# --- test code ---
import
SimPy.SimulationTrace as Sim
class
Test(Sim.Process):
def __init__(self,
name):
Sim.Process.__init__(self, name=name)
def
be_interrupted(self):
print
self.name, "waiting to be
interrupted..."
yield
Sim.hold, self, 50
while
self.interrupted():
self.interruptReset()
yield Sim.hold, self, self.interruptLeft
def interrupt_other(self,
other):
yield Sim.hold, self,
5
self.interrupt(other)
Sim.initialize()
t1 = Test('t1')
t2 =
Test('t2')
t3 = Test('t3')
Sim.activate(t1,
t1.be_interrupted())
Sim.activate(t2,
t2.interrupt_other(t1))
Sim.activate(t3,
t3.interrupt_other(t1))
Sim.simulate(until=50)
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users