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.

classification
Title: no way to introspect registered atexit handlers
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: barry, cjw296, iritkatriel, neologix, pitrou
Priority: normal Keywords:

Created on 2013-02-11 22:35 by cjw296, last changed 2022-04-11 14:57 by admin.

Messages (8)
msg181935 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2013-02-11 22:35
Python 2 had a private but usable way of introspecting and manipulating registered atexit handlers by way of the atexit._exithandlers.

In Python 3, registering and unregistering are handled, but there is no longer a way to see what atexit handlers are registered.

Barry suggested filing a bug to have this added as a new feature for Python 3.4. Some kind of read-only sequence would be fine, if the original list can no longer be exposed.
msg182683 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-02-22 18:49
Could you please give an example of why this would be a useful addition?
I can see the usage of removing a handler, but the user should know which handlers are registered.
msg182684 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2013-02-22 18:51
Barry advised me to open this issue as it's a functional regression from Python 2.

My use case is unit testing code that registers atexit handlers and making sure the right handlers are registered with the correct parameters.
msg182685 - (view) Author: Charles-François Natali (neologix) * (Python committer) Date: 2013-02-22 18:54
> Barry advised me to open this issue as it's a functional regression from Python 2.

But it was relying on a private and non documented feature in Python
2, so it's not really a regression.

> My use case is unit testing code that registers atexit handlers and making sure the right handlers are registered with the correct parameters.

IMO, complicating an API for testing purpose is a bad idea.
msg182686 - (view) Author: Chris Withers (cjw296) * (Python committer) Date: 2013-02-22 18:55
I can think of other use cases. Anyway, I'm just glad your opinion isn't the only one there is ;-)
msg182688 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-02-22 19:08
I don't think you want your test suite to run your atexit handlers at exit, so you should probably mock atexit.register instead.
msg182692 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2013-02-22 19:41
On Feb 22, 2013, at 06:54 PM, Charles-François Natali wrote:

>Charles-François Natali added the comment:
>
>> Barry advised me to open this issue as it's a functional regression from
>> Python 2.
>
>But it was relying on a private and non documented feature in Python
>2, so it's not really a regression.

I also suggested it would have to be considered a new feature for 3.4.
msg396594 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-06-27 18:47
See also issue32082.
History
Date User Action Args
2022-04-11 14:57:41adminsetgithub: 61388
2021-11-30 16:59:52iritkatrielsettype: enhancement
components: + Library (Lib)
versions: + Python 3.11, - Python 3.4
2021-11-24 12:04:44iritkatriellinkissue32082 superseder
2021-06-27 18:47:23iritkatrielsetnosy: + iritkatriel
messages: + msg396594
2013-02-22 19:41:54barrysetmessages: + msg182692
2013-02-22 19:08:08pitrousetnosy: + pitrou
messages: + msg182688
2013-02-22 18:55:26cjw296setmessages: + msg182686
2013-02-22 18:54:20neologixsetmessages: + msg182685
2013-02-22 18:51:28cjw296setmessages: + msg182684
2013-02-22 18:49:20neologixsetnosy: + neologix
messages: + msg182683
2013-02-20 22:20:43barrysetnosy: + barry
2013-02-11 22:35:30cjw296create