[New-bugs-announce] [issue46115] Interrupting subprocess.popen in recursive calls by KeyboardInterrupt causes Fatal Python error.

Xinmeng Xia report at bugs.python.org
Fri Dec 17 06:14:30 EST 2021


New submission from Xinmeng Xia <xiaxm at smail.nju.edu.cn>:

Popen works when stdio fds are available. However, when interrupting popen in a recursive function call. The Python interpreter reports a Fatal Python error.

test.py
========================================
import subprocess
import os
import sys


def test_small_errpipe_write_fd():
    new_stdout = os.dup(1)
    try:
        os.close(1)
        subprocess.Popen([sys.executable, '-c', "print('AssertionError:0:CLOEXEC failure.')"]).wait()
    finally:
        os.dup2(new_stdout, 0)
        os.dup2(new_stdout, 1)
        test_small_errpipe_write_fd()

test_small_errpipe_write_fd()
=======================================

Reported message:
---------------------------------------------
xxm at xxm:~$ 'cpython-main/python' '/home/xxm/Desktop/test/test.py' 
^CFatal Python error: init_import_site: Failed to import the site module
Python runtime state: initialized
Traceback (most recent call last):
  File "/home/xxm/Desktop/compilers/cpython-main/Lib/site.py", line 73, in <module>
    import os
    ^^^^^^^^^
  File "/home/xxm/Desktop/compilers/cpython-main/Lib/os.py", line 29, in <module>
    from _collections_abc import _check_methods
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/Desktop/compilers/cpython-main/Lib/_collections_abc.py", line 1015, in <module>
    class Sequence(Reversible, Collection):
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/xxm/Desktop/compilers/cpython-main/Lib/abc.py", line 106, in __new__
    cls = super().__new__(mcls, name, bases, namespace, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyboardInterrupt
-----------------------------------------------

Reproduce step:
1. run test.py in the console
2. use "Ctrl C" to interrupt the program

If typing a "Ctrl C", the program does not stop and no error is reported. Just type "Ctrl C" constantly. Sometimes, it need 5 or 6 "Ctrl C" to reproduce this bug. 



verson of Python: Python 3.11.0a2+ (main, Nov 26 2021, 18:38:48) [GCC 7.5.0] on linux (it also crashes Python 3.6.15, 3.7.12,3.8.12)

----------
components: Interpreter Core
messages: 408772
nosy: xxm
priority: normal
severity: normal
status: open
title: Interrupting subprocess.popen in recursive calls by KeyboardInterrupt causes Fatal Python error.
type: crash
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46115>
_______________________________________


More information about the New-bugs-announce mailing list