[PyPy-issue] [issue693] Documentation needed: Coroutine garbage collection
pypy-dev-issue at codespeak.net
Tue Apr 26 10:40:57 CEST 2011
Chris Smowton <cs448 at cam.ac.uk> added the comment:
Nearly, but I'm not sure the "executed only after the .kill has finished" bit is
true! Here's an example session:
>>>> import gc
>>>> import stackless
>>>> def f():
.... print "Start F!"
.... print "End F!"
.... except CoroutineExit:
.... print "F: killed; switching to main"
.... print "F: back in EH?"
>>>> def g():
.... print "Start G!"
.... print "End G!"
>>>> main_coro = stackless.coroutine.getcurrent()
>>>> coro1 = stackless.coroutine()
>>>> coro2 = stackless.coroutine()
>>>> del coro1
F: killed; switching to main
Because F catches the CoroutineExit exception, we *never* end up in coro2! If
there's any possibility a coroutine will be GC'd and will catch that call, the
programmer will need to instrument their coroutines to figure out what actually
got executed and re-issue the coro2.switch() at the next opportunity.
This doesn't seem good -- if there's any possibility a coroutine might become
garbage, the programmer will need to instrument their coroutines in order to
work out that this happened and re-issue the switch. I'm not sure what the right
thing to do would be here?
PyPy development tracker <pypy-dev-issue at codespeak.net>
More information about the Pypy-issue