This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients gregory.p.smith, izbyshev, jbms, vstinner
Date 2021-09-24.11:27:45
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1632482865.19.0.756989389657.issue42969@roundup.psfhosted.org>
In-reply-to
Content
Gregory P. Smith: Python has many API using callbacks:

PEP 445 added PyMem_SetAllocator() to set memory allocator. Adding PyMem_GetAllocator() also made possible to chain allocators and to "hook" into an existing allocator to execute code before and after it's called (the PEP contains an example).

I'm not sure if it's important or useless to chain callbacks with Py_SetThreadExitCallback(). I suggest to always override the previously set callback.

It would matter if library A sets a callback to emit log and library B sets a callback to hang threads. It maybe be nice to first emit a log and then hang the thread. But then the order in which callbacks are set starts to matter a lot :-)

I'm fine with adding Py_GetThreadExitCallback() if you consider that it matters.


> If someone passes nullptr does that undo it (please no!).

I don't think that we should bother with adding a special case. I prefer to consider developers as adults and let them make their own mistakes if they consider that they understand the code well enough ;-)

_PyEval_SetTrace() allows to remove the current trace function. It's a legit use case.

If library C is annoyed by library A and library B installed annoying callbacks, IMO it's also ok to let it "remove" the previously set callback, no?

IMO Py_SetThreadExitCallback(NULL) should simply set the callback to NULL, so restore the default behavior: call pthread_exit().
History
Date User Action Args
2021-09-24 11:27:45vstinnersetrecipients: + vstinner, gregory.p.smith, izbyshev, jbms
2021-09-24 11:27:45vstinnersetmessageid: <1632482865.19.0.756989389657.issue42969@roundup.psfhosted.org>
2021-09-24 11:27:45vstinnerlinkissue42969 messages
2021-09-24 11:27:45vstinnercreate