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: Offer error context manager for code.interact
Type: enhancement Stage: resolved
Components: Library (Lib) Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Claudiu Saftoiu, berker.peksag
Priority: normal Keywords:

Created on 2016-07-18 19:31 by Claudiu Saftoiu, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg270786 - (view) Author: Claudiu Saftoiu (Claudiu Saftoiu) Date: 2016-07-18 19:31
When debugging code that raises unexpected exceptions, I often find myself doing this:

    try:
        some_code
    except:
        import code; code.interact(local=locals())
        raise

My suggestion is a context manager to make this less verbose:

    with code.interact_on_error():
        some_code

The effect would be the same: if an exception is caught, `code.interact` is called with the locals of the function, and re-raised when `code.interact` ends.
msg277635 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-09-28 15:05
Hi Claudiu, thanks for the report, but I don't think this is a common use case that needs to be supported in the standard library. Other people may prefer to use different solutions in a similar case (e.g. using a debugger) Plus, it's not hard to implement this as a custom context manager in your code.
History
Date User Action Args
2022-04-11 14:58:33adminsetgithub: 71752
2016-09-28 15:05:12berker.peksagsetstatus: open -> closed

nosy: + berker.peksag
messages: + msg277635

resolution: rejected
stage: resolved
2016-07-18 19:31:04Claudiu Saftoiucreate