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

Add a function to know about interpreter shutdown #66885

Closed
pitrou opened this issue Oct 22, 2014 · 16 comments
Closed

Add a function to know about interpreter shutdown #66885

pitrou opened this issue Oct 22, 2014 · 16 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement

Comments

@pitrou
Copy link
Member

pitrou commented Oct 22, 2014

BPO 22696
Nosy @pitrou, @vstinner, @serhiy-storchaka
Files
  • is_finalizing.patch
  • traceback_ignore_linecache_error.patch
  • is_finalizing2.patch
  • 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 = <Date 2014-12-07.00:30:35.648>
    created_at = <Date 2014-10-22.12:20:53.014>
    labels = ['interpreter-core', 'type-feature']
    title = 'Add a function to know about interpreter shutdown'
    updated_at = <Date 2015-01-06.00:34:40.838>
    user = 'https://github.com/pitrou'

    bugs.python.org fields:

    activity = <Date 2015-01-06.00:34:40.838>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2014-12-07.00:30:35.648>
    closer = 'pitrou'
    components = ['Interpreter Core']
    creation = <Date 2014-10-22.12:20:53.014>
    creator = 'pitrou'
    dependencies = []
    files = ['36992', '37365', '37369']
    hgrepos = []
    issue_num = 22696
    keywords = ['patch']
    message_count = 16.0
    messages = ['229817', '229818', '229820', '229823', '229824', '231248', '231364', '232178', '232186', '232200', '232210', '232212', '232218', '232261', '232262', '233494']
    nosy_count = 5.0
    nosy_names = ['pitrou', 'vstinner', 'Arfrever', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue22696'
    versions = ['Python 3.5']

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 22, 2014

    I propose to add a new function sys.shutting_down() (name debatable) returning True if the interpreter is currently shutting down.

    This would be a function so that you can bind it and avoid having it wiped at shutdown :-)

    @pitrou pitrou added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement labels Oct 22, 2014
    @vstinner
    Copy link
    Member

    For the issue bpo-22599, I wrote a patch but then I removed my patch and reverted my changed...

    Here is a new patch which implements why I already wrote: add a new sys._is_finalizing() function, with a unit test.

    I propose to add a new function sys.shutting_down() (name debatable)

    The name sounds like a function to shut down the computer or exit Python.

    I don't like _is_finalizing() name neither :-)

    My patch uses a private function which is CPython specific. Does it make sense to add a public function instead? Is it possible to implement it in any Python implementation (PyPy, IronPython, Jython, etC.)? I guess that the most dummy implementation is to always return False (Python is always running.

    @serhiy-storchaka
    Copy link
    Member

    Are there other special interpreter states about which it would by helpful to
    know? Interpreter initializing, garbage collecting, signal handling?

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 22, 2014

    My patch uses a private function which is CPython specific.
    Does it make sense to add a public function instead?

    I would like it to be public. It can be useful in __del__ methods and the like.

    @pitrou
    Copy link
    Member Author

    pitrou commented Oct 22, 2014

    Are there other special interpreter states about which it would by
    helpful to know? Interpreter initializing, garbage collecting, signal
    handling?

    • interpreter initializing: user code generally isn't executed in that phase
    • garbage collecting: there are already garbage collection callbacks
    • signal handling: well... I don't see why that would be useful

    @serhiy-storchaka
    Copy link
    Member

    I'm +0 for is_finalizing.

    There is a typo in the docstring.

    @serhiy-storchaka
    Copy link
    Member

    An indirect way how to know about interpreter shutdown -- test existing of the path attribute in sys (bpo-20603).

    @serhiy-storchaka
    Copy link
    Member

    After solving this issue we should reconsider the traceback_ignore_linecache_error.patch patch in bpo-22599.

    @vstinner
    Copy link
    Member

    vstinner commented Dec 5, 2014

    After solving this issue we should reconsider the traceback_ignore_linecache_error.patch patch in bpo-22599.

    I reposted the patch in this issue since I just closed the issue bpo-22599.

    @pitrou
    Copy link
    Member Author

    pitrou commented Dec 5, 2014

    Here is a patch with docs.

    @vstinner
    Copy link
    Member

    vstinner commented Dec 5, 2014

    is_finalizing2.patch looks good to me.

    @serhiy-storchaka
    Copy link
    Member

    Before committing the patch it will be good to find places in the code which will benefit from this function.

    And please don't forget to fix a typo in the docstring.

    @vstinner
    Copy link
    Member

    vstinner commented Dec 5, 2014

    Before committing the patch it will be good to find places in the code which will benefit from this function.

    The traceback and/or the linecache is a first good candidate to use this new function. We may patch more functions later if needed, I don't think that we need to address all issues right now.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Dec 7, 2014

    New changeset 7f3695701724 by Antoine Pitrou in branch 'default':
    Issue bpo-22696: Add function :func:`sys.is_finalizing` to know about interpreter shutdown.
    https://hg.python.org/cpython/rev/7f3695701724

    @pitrou
    Copy link
    Member Author

    pitrou commented Dec 7, 2014

    Using the function in the stdlib can be done separately. I fixed the typo in the docstring. Thanks!

    @pitrou pitrou closed this as completed Dec 7, 2014
    @vstinner
    Copy link
    Member

    vstinner commented Jan 6, 2015

    Using the function in the stdlib can be done separately.

    Is there an open issue for that?

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    interpreter-core (Objects, Python, Grammar, and Parser dirs) type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    3 participants