-
Notifications
You must be signed in to change notification settings - Fork 62
Stackless issue #192: use tp_finalize instead of tp_dealloc for tasklet finalisation #194
Conversation
"Revert the patch, that added the function PyObject_GC_Collectable()," ah, that old chestnut. Yes, the intention was that objects could not be determined on a per-type basis to be collectable, but it depended on their actual runtime state. A tasklet could not be collected if it contained non-trivial stack state, for instance. I gather that Pep 442 must then provide for similar functionality. |
@kristjanvalur Yes, PEP 442 provides reliable finalisers. Because the object is still intact when the finaliser runs, the finaliser can safely create a new reference, if the object is must not be collected. |
…code Refactor the finalisation code of stackless.tasklet and stackless.channel. - For tasklets, use a PEP 442 finalizer; - for channels a simple tp_clear function is sufficient. Like every PEP 442 other finalizer, the new finalizer runs only once for each tasklet.
In order to prevent an endless loop in the tasklet-finalizer, try at most 10 times to kill a tasklet.
Move the handling of tasklets with non-trivial C-state from tasklet_traverse to tasklet_finalize. If a tasklet still has a non-trivial C-state after killing the tasklet, the finalizer appends the tasklet to gc.garbage. Now de-allocation caused by ref-counting behaves identically to de-allocation caused by GC. The gc-patch introduced by stackless-dev/stackless_historic@35ba34f18 is now obsolete.
Revert the patch, that added the function PyObject_GC_Collectable(). It was introduced by stackless-dev/stackless_historic@35ba34f18. See bpo-9141 for a discussion of this interesting patch.
5518256
to
1786ba4
Compare
I didn't get any negative feedback yet. Therefore I'll commit the PR. |
Manually merged |
Refactor the finalisation code of tasklet and channel. For tasklet use a PEP 442 finaliser. Channel does not need a finaliser, a simple tp_clear function is enough.
For dying tasklets with non trivial C-state de-allocation caused by ref-counting now behaves identically to de-allocation caused by GC. If a tasklet still has a non-trivial C-state after killing the tasklet, the finalizer appends the tasklet to gc.garbage.
Revert the patch, that added the function PyObject_GC_Collectable(), because it is now obsolete. It was introduced by stackless-dev/stackless_historic@35ba34f18. See bpo-9141 for a discussion about this interesting patch.