[Stackless] Modelling simulated time and granular interruptions

stackless at kaishaku.org stackless at kaishaku.org
Mon Jul 3 18:45:16 CEST 2006


I am writing a non-realtime proof-of-concept simulation.

I have Actors. They perform actions which take a specific
amount of time. The trouble is, Actors can be interrupted
while performing an action and could cancel that action.

I would like to know how I should implement cancellation
of actions with stackless. I see two obvious possibilities:

1) Call the action function many times, with each call
   representing a sub-second slice of time, my "tick".

    # for this example, it takes 1 tick to say 1 char
    def say(self,ticks,s):
      i = 0     
      while i!=ticks:
        if i==len(s): break
        print s[i],
        i += 1 
      return ticks-i, s[i:]

2) Call the action function once, but allow it to be
   paused, resumed or cancelled. I am not sure how
   this is done. Would I place interrupt possibilities
   at many/key points in the function? Is there a
   better way?

    # "event" can pause, resume, or cancel the action
    def say(self,s):
      i = 0      
      while i!=len(s):
        print s[i],
        i += 1
        if ...event...: break;
    

I imagine the 2nd method is better, but I am not sure
how it should be implemented, particularly in my system.

However, I also imagine the first option is more elegant
and understandable in the flow of things. This may be
purely my imagination and lack of stackless experience.

I plan to have a 2 dozen actors, and plan to perform
actions over a simulated period of 2 hours.

The integrity of the simulated time is important. I do not
want an actor from the future interacting with another still
living in the past simply because of the way the scheduling
worked out. Some ideas have introduced that possibility. :p

I am looking for a great solution using stackless techniques.

-- 
 kai


_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list