Alan Marchiori | 8 Dec 00:11

Re: queueing activations?

Yes, the program you have would produce the output I wanted...

But, the example I gave was just for illustration.  In my real
application I have many asynchronous processes that may or may not
(re)activate other processes (depending on input data).  But if a
process is reactivated more than once only the _last_ one is
scheduled.  The problem with what you wrote is the Process that gets
activated doesn't know the next time it will be activated (because
this information comes from another process) so it cannot do a yield
hold.

I must be misusing SimPy in this case.  I am looking into using a
Resource object to queue the activations, but I'm not entirely sure
that's what I want.

And callback is from being a C programmer for many years, since the
PEM is a callback function pointer (if I understand this correctly),
but PEM is what I mean.

Thanks,

On Mon, Dec 7, 2009 at 3:24 PM, Tony Vignaux <vignaux <at> gmail.com> wrote:
> Alan,
>
> I am not quite sure what you are trying to do and, in particular, the use of
> the name callback for the PEM confuses me.
> I THINK that the following program is what you are after. I have changed the
> identifier of the PEM to pem.
>
> from SimPy.Simulation import *
>
> class AProcess(Process):
>    def __init__(self):
>        Process.__init__(self)
>    def pem(self):
>        while now() <= 12:
>            print "awake at", now()
>            yield hold,self,1
>
>
> def main():
>    initialize() # required
>    a = AProcess()
>    activate(a, a.pem(), at=10.0)
>    simulate(until=100)
>
> if __name__ == '__main__': main()
>
>
> On Tue, Dec 8, 2009 at 7:50 AM, Alan Marchiori <alan <at> alanmarian.com> wrote:
>>
>> Hi,
>>
>> I'm just getting started with SimPy and maybe am a bit confused about
>> how to queue events... I made this simple example:
>>
>> <code>
>> from SimPy.Simulation import *
>>
>> class AProcess(Process):
>>    def __init__(self):
>>        Process.__init__(self)
>>    def callback(self):
>>        while True:
>>            print "awake at", now()
>>            yield passivate, self
>>
>> def main():
>>    initialize() # required
>>
>>    a = AProcess()
>>
>>    activate(a, a.callback(), at=10.0)
>>    reactivate(a, at=11)
>>    reactivate(a, at=12)
>>
>>    simulate(until=100)
>>
>> if __name__ == '__main__': main()
>> </code>
>>
>> the output is:
>> awake at 12
>>
>>
>> I expected the output to be:
>> awake at 10
>> awake at 11
>> awake at 12
>>
>> Is this sort of behavior possible (where activations are queued?) ?
>>
>> Thanks,
>>
>>
>> ------------------------------------------------------------------------------
>> Join us December 9, 2009 for the Red Hat Virtual Experience,
>> a free event focused on virtualization and cloud computing.
>> Attend in-depth sessions from your desk. Your couch. Anywhere.
>> http://p.sf.net/sfu/redhat-sfdev2dev
>> _______________________________________________
>> Simpy-users mailing list
>> Simpy-users <at> lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/simpy-users
>
>

------------------------------------------------------------------------------
Return on Information:
Google Enterprise Search pays you back
Get the facts.
http://p.sf.net/sfu/google-dev2dev

Gmane