Re: SimPy waitevent activations
kgmuller <kgmuller <at> xs4all.nl>
2007-12-21 13:07:20 GMT
Srikanth,
you get this from the multiple activation of the
Responder processes. You should activate a Process instance only
once.
So, here is a better structure for your
test:
from SimPy.Simulation import
*
class Responder(Process)
:
def
respond(self,ev):
while
True:
print "Inside respond() of
%s"%self.name
yield
waitevent,self,ev
print "%s got signal"%self.name
class
Scheduler(Process):
def schedule(self,ev):
while
True:
ev.signal
()
print
"Sent a signal %s"
%ev.name
yield hold,self,1
def execute():
print "\n"*5
print "-"*10
initialize()
resp1 = Responder("Responder
1")
resp2 = Responder("Responder 2")
resp3 = Responder("Responder 3")
sig =
SimEvent()
activate(resp1,resp1.respond(sig))
activate(resp2,resp2.respond(sig))
activate(resp3,resp3.respond(sig))
s =
Scheduler()
activate(s,s.schedule(sig))
simulate(until=1)
if __name__ ==
'__main__':
execute()
When
run, you get:
----------
Inside respond() of
Responder 1
Inside respond() of Responder 2
Inside respond() of Responder
3
Sent a signal a_SimEvent
Responder 3 got signal
Inside respond() of
Responder 3
Responder 2 got signal
Inside respond() of Responder
2
Responder 1 got signal
Inside respond() of Responder 1
Sent a signal
a_SimEvent
Responder 1 got signal
Inside respond() of Responder
1
Responder 2 got signal
Inside respond() of Responder 2
Responder 3
got signal
Inside respond() of Responder 3
Which
is perfectly ok.
Klaus
Hello,
I am a newbie user of SimPy and am new to simulation in
general. I have written a small SimPy program to understand how the signalling
via waitevent works. The following is the
program:
#-------------------------------begin code
--------------------------------------------------
from SimPy.Simulation
import *
class Responder(Process) :
def
respond(self,ev):
while
True:
print "Inside respond() of
%s"%self.name
yield waitevent,self,ev
class Scheduler(Process):
def
schedule(self):
resp1 =
Responder("Responder 1")
resp2 =
Responder("Responder 2")
resp3 =
Responder("Responder 3")
sig =
SimEvent()
while
True:
activate(resp1,resp1.respond(sig))
activate(resp2,resp2.respond(sig))
activate(resp3,resp3.respond(sig))
sig.signal
()
print
"Sent a signal %s"
%sig.name
yield hold,self,1
def
execute():
print "\n"*5
print
"-"*10
initialize()
s =
Scheduler()
activate(s,s.schedule())
simulate(until=1)
if
__name__ == '__main__':
execute()
#-------------------------------end code
-----------------------------------------------------
For the sake of
simplicity, I ran the simulation for one time click, however, the results look
similar for other iterations, too.
The following is the
output
#-----------------------------------begin
output---------------------------------------------
Inside respond() of
Responder 1
Inside respond() of Responder 1
Inside respond() of
Responder 2
Inside respond() of Responder 3
Sent a signal
a_SimEvent
Inside respond() of Responder 3
Inside respond() of
Responder 2
Inside respond() of Responder
1
#-----------------------------------end
output------------------------------------------------
My question is
this: why does the process execution method (PEM) of the Responder 1 object
get called twice the first time - I expected it to be called only once. Any
explanation that anyone on the list can provide is greatly appreciated.
Thanks in advance.
Srikanth.
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Simpy-users mailing list
Simpy-users <at> lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/simpy-users