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: Fatal Python Error when Python startup is interrupted by CTRL+c
Type: Stage:
Components: Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, brett.cannon, r.david.murray, skrah, terry.reedy, vstinner
Priority: normal Keywords:

Created on 2012-04-20 00:01 by vstinner, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (10)
msg158782 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-20 00:01
If you press CTRL+c while Python is starting, you may get such error:

^CFatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 990, in _find_and_load
  File "<frozen importlib._bootstrap>", line 571, in load_module
  File "<frozen importlib._bootstrap>", line 228, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 456, in _load_module
  File "/home/haypo/prog/python/default/Lib/io.py", line 90, in <module>
    RawIOBase.register(FileIO)
  File "/home/haypo/prog/python/default/Lib/abc.py", line 155, in register
    if issubclass(subclass, cls):
  File "/home/haypo/prog/python/default/Lib/abc.py", line 201, in __subclasscheck__
    elif subclass in cls._abc_negative_cache:
KeyboardInterrupt
Abandon
msg158791 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-04-20 03:01
OK, so what's your point? =) I mean you stopped the interpreter while in the middle of starting up. Do you want to trigger a fatal error if the exception raised was KeyboardInterrupt?
msg158794 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-04-20 04:37
I think Victor's point was that you get the "can't initialize standard streams" in addition to the KeyboardInterrupt (but I'm just guessing).

(See issue 14228 for examples of what normally happens on a startup KeyboardInterrupt.)
msg158804 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-04-20 08:13
> OK, so what's your point? =)

In Python < 3.3, CTRL+c at startup fails with "Traceback: ...", not
with a fatal error. A fatal error may dump a core dump and open a
popup on Windows.
msg158835 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-04-20 15:16
Welcome to Python code running during startup. =) As I said, the only thing I can think of is raising the exception instead of catching it and immediately triggering the fatal exception, but that specific fatal error was not introduced by me so this is just a side-effect of having Python code running during startup.
msg158840 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-04-20 15:25
Hmm, I've managed to produce the error with 3.1:

$ python3.1
Fatal Python error: Py_Initialize: can't initialize sys standard streams
Traceback (most recent call last):
  File "/usr/lib/python3.1/io.py", line 60, in <module>
    import _io
  File "/usr/lib/python3.1/os.py", line 380, in <module>
    from _abcoll import MutableMapping  # Can't use collections (bootstrap)
  File "/usr/lib/python3.1/encodings/iso8859_15.py", line 14, in decode
    def decode(self,input,errors='strict'):
KeyboardInterrupt
Aborted
msg158844 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2012-04-20 15:34
So importlib just increased the window of vulnerability for this kind of thing.
msg158845 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2012-04-20 15:47
The funny thing is, in 3.3 I can't reproduce it (i.e. I only get
the KeyboardInterrupt). So I'm not sure if this happens more often
now.


^CTraceback (most recent call last):
  File "<frozen importlib._bootstrap>", line 989, in _find_and_load
  File "<frozen importlib._bootstrap>", line 571, in load_module
  File "<frozen importlib._bootstrap>", line 228, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 456, in _load_module
  File "/home/stefan/pydev/cpython/Lib/site.py", line 537, in <module>
    main()
 [...]
  File "/home/stefan/pydev/cpython/Lib/collections/__init__.py", line 322, in namedtuple
    field_names = list(map(str, field_names))
KeyboardInterrupt
msg158873 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-04-20 19:14
In a running interpreter and Idle, ^C results in
KeyboardInterrupt
>>> 
and nothing else.

From a command line, I think
KeyboardInterrupt: Python startup stopped"
<cli prompt>
would be ideal.

On Windows, I do not know if a program started from an icon, shortcut, or explorer *can* be interrupted, except possibly with Task Manager if the entry shows up fast enough, as it should not get keyboard focus until started.
msg162427 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-06-06 22:59
> Hmm, I've managed to produce the error with 3.1:

Oh oh, I thought that importlib changed the behaviour, but I'm wrong. importlib doesn't change anything so I'm closing the issue as invalid.
History
Date User Action Args
2022-04-11 14:57:29adminsetgithub: 58832
2012-06-06 22:59:25vstinnersetstatus: open -> closed
resolution: not a bug
messages: + msg162427
2012-04-20 19:14:38terry.reedysetnosy: + terry.reedy
messages: + msg158873
2012-04-20 15:47:07skrahsetmessages: + msg158845
2012-04-20 15:34:58brett.cannonsetmessages: + msg158844
2012-04-20 15:25:41skrahsetnosy: + skrah
messages: + msg158840
2012-04-20 15:16:24brett.cannonsetmessages: + msg158835
2012-04-20 08:13:49vstinnersetmessages: + msg158804
2012-04-20 04:37:43r.david.murraysetnosy: + r.david.murray
messages: + msg158794
2012-04-20 03:01:42brett.cannonsetmessages: + msg158791
2012-04-20 02:30:09Arfreversetnosy: + Arfrever
2012-04-20 00:01:21vstinnercreate