[PEAK] trellis activity does not save/restore Contextual context
between task switches
Andrew Svetlov
andrew.svetlov at gmail.com
Sat Mar 21 21:47:42 EDT 2009
>> I made patch for TaskCell._stepper to support this feature. Main
>> change is: STACK now contains not only current generators for tasks
>> but also last context.State for every generator and updates states
>> when need.
>
> Is that really necessary? It seems to me that you should only need one
> saved state for the entire task, and simply swap it in and out around the
> send/throw/next call.
>
You true, really I need to save only 'current' state for task, switch
to this state at start of _step and restore state at function exit.
---------------
def _stepper(self, func):
VALUE = self._result = []
ERROR = self._error = []
STACK = [func()]
CALL = STACK.append
RETURN = STACK.pop
ctrl = trellis.ctrl
STATE = [context.State.child()]
def _step():
outer = STATE[0].swap()
while STACK:
try:
it = STACK[-1]
if VALUE and hasattr(it, 'send'):
rv = it.send(VALUE[0])
elif ERROR and hasattr(it, 'throw'):
rv = it.throw(*ERROR.pop())
else:
rv = it.next()
except:
del VALUE[:]
ERROR.append(sys.exc_info())
if ERROR[-1][0] is StopIteration:
ERROR.pop() # not really an error
RETURN()
else:
del VALUE[:]
if rv is Pause:
break
elif hasattr(rv, 'next'):
CALL(rv); continue
elif isinstance(rv, Return):
rv = rv.value
VALUE.append(rv)
if len(STACK)==1:
break
RETURN()
if STACK and not ERROR and not ctrl.reads:
ctrl.current_listener.dirty() # re-run if still running
STATE[0] = outer.swap()
return resume()
return _step
---------------
>
>> Please review and if this patch is clean - put it into current trellis
>> trunk.
>> If not - please point where I'm wrong.
>
> It doesn't appear that you've actually provided a patch, and it does
> something involving some "fds_main.utilities.trellis" module in any event.
> Tests should be either a doctest or a patch to the test_trellis module.
>
I can send you svn diff for activity.py and test_trellis,py modules. Is it ok?
Thank you for feedback.
More information about the PEAK
mailing list