Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no way to introspect registered atexit handlers #61388

Open
cjw296 opened this issue Feb 11, 2013 · 10 comments
Open

no way to introspect registered atexit handlers #61388

cjw296 opened this issue Feb 11, 2013 · 10 comments
Labels
3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@cjw296
Copy link
Contributor

cjw296 commented Feb 11, 2013

BPO 17186
Nosy @warsaw, @pitrou, @cjw296, @iritkatriel

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2013-02-11.22:35:30.870>
labels = ['type-feature', 'library', '3.11']
title = 'no way to introspect registered atexit handlers'
updated_at = <Date 2021-11-30.16:59:52.647>
user = 'https://github.com/cjw296'

bugs.python.org fields:

activity = <Date 2021-11-30.16:59:52.647>
actor = 'iritkatriel'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2013-02-11.22:35:30.870>
creator = 'cjw296'
dependencies = []
files = []
hgrepos = []
issue_num = 17186
keywords = []
message_count = 8.0
messages = ['181935', '182683', '182684', '182685', '182686', '182688', '182692', '396594']
nosy_count = 5.0
nosy_names = ['barry', 'pitrou', 'cjw296', 'neologix', 'iritkatriel']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue17186'
versions = ['Python 3.11']

@cjw296
Copy link
Contributor Author

cjw296 commented Feb 11, 2013

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.

@neologix
Copy link
Mannequin

neologix mannequin commented Feb 22, 2013

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.

@cjw296
Copy link
Contributor Author

cjw296 commented Feb 22, 2013

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.

@neologix
Copy link
Mannequin

neologix mannequin commented Feb 22, 2013

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.

@cjw296
Copy link
Contributor Author

cjw296 commented Feb 22, 2013

I can think of other use cases. Anyway, I'm just glad your opinion isn't the only one there is ;-)

@pitrou
Copy link
Member

pitrou commented Feb 22, 2013

I don't think you want your test suite to run your atexit handlers at exit, so you should probably mock atexit.register instead.

@warsaw
Copy link
Member

warsaw commented Feb 22, 2013

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.

@iritkatriel
Copy link
Member

See also bpo-32082.

@iritkatriel iritkatriel added stdlib Python modules in the Lib dir 3.11 only security fixes type-feature A feature request or enhancement labels Nov 30, 2021
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added 3.13 new features, bugs and security fixes and removed 3.11 only security fixes labels May 15, 2023
@matthiasdiener
Copy link
Contributor

A hacky way to see which handlers are registered is discussed here: https://stackoverflow.com/a/63029332/1250282.

@cjw296
Copy link
Contributor Author

cjw296 commented Oct 18, 2023

It's sad that this hack is needed, I really do think there should be a way to introspect what exit handler are currently registered. New feature or regression from 2.7, either way, it would be great to have this functionality given the set of folks that want it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 new features, bugs and security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

5 participants