Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Stackless issue #192: use tp_finalize instead of tp_dealloc for tasklet finalisation - #194

Closed
akruis wants to merge 8 commits into
stackless-dev:master-slpfrom
akruis:slp-issue-192
Closed

akruis wants to merge 8 commits into
stackless-dev:master-slpfrom
akruis:slp-issue-192

Conversation

@akruis

@akruis akruis commented Dec 28, 2018

Copy link
Copy Markdown

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.

@kristjanvalur

Copy link
Copy Markdown
Collaborator

"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.

@akruis

akruis commented Dec 29, 2018

Copy link
Copy Markdown
Author

@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.
In our case I append tasklets with non trivial C-state to gc.garbage.

…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.
@akruis

akruis commented Jan 12, 2019

Copy link
Copy Markdown
Author

I didn't get any negative feedback yet. Therefore I'll commit the PR.

@akruis

akruis commented Jan 12, 2019

Copy link
Copy Markdown
Author

Manually merged

@akruis akruis closed this Jan 12, 2019
@akruis
akruis deleted the slp-issue-192 branch January 12, 2019 12:27
@akruis akruis mentioned this pull request Jan 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants