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 ishimoto
Recipients ishimoto
Date 2019-03-02.06:10:23
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1551507024.01.0.06569662724.issue36164@roundup.psfhosted.org>
In-reply-to
Content
I sometime use a hack to start interactive console after running script.

.. code-block:: python

   import os

   os.environ['PYTHONINSPECT'] = 'x'
   print("Hello")

This hack works because ``PYTHONINSPECT`` is checked `here <https://github.com/python/cpython/blob/master/Modules/main.c#L738>`__ when exiting Python.

However, if the script uses ``sys.exit()`` to exit from Python, interactive console doen't apper because unhandled ``SystemExit`` exception leads ``exit()`` call to kill process, without checking ``PYTHONINSPECT``.

.. code-block:: python

   import os, sys

   os.environ['PYTHONINSPECT'] = 'x'
   print("Hello")

   sys.exit(1)  # Interactive console will not start


I think feature to allow updating ``Py_InspectFlag`` is useful, and this is a bugs to be fixed. However, setting environment variable to start console is not intuituve.

So instead of fixing bug, I would like to propose a small function to set ``Py_InspectFlag`` to start interactive console after running script.

.. code-block:: python

    sys.setinteractiveflag(bool)

Thoughts?
History
Date User Action Args
2019-03-02 06:10:24ishimotosetrecipients: + ishimoto
2019-03-02 06:10:24ishimotosetmessageid: <1551507024.01.0.06569662724.issue36164@roundup.psfhosted.org>
2019-03-02 06:10:23ishimotolinkissue36164 messages
2019-03-02 06:10:23ishimotocreate