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 Zhipeng Xie
Recipients Zhipeng Xie
Date 2019-10-24.07:38:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571902719.3.0.191965904237.issue38575@roundup.psfhosted.org>
In-reply-to
Content
Hi, we had a child process deadlock on _disabling_gc_lock in subprocess.Popen. It seems that after https://github.com/python/cpython/commit/5e8e371364ee58dadb9a4e4e51c7e9cf6bedbfae, subprocess.Popen no longer support to be called in preexec_fn.

Steps to reproduce:
[root@localhost ~]# python2 --version
Python 2.7.15
[root@localhost ~]# python2 mtfork.py 

wait for a while and the child process deadlock

Here is the gdb stack:

(gdb) py-bt
Traceback (most recent call first):
  Waiting for the GIL
  File "/usr/local/lib/python2.7/subprocess.py", line 931, in _execute_child
    with self._disabling_gc_lock:
  File "/usr/local/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "mtfork.py", line 36, in run_cmd
    stderr=subprocess.PIPE)
  File "/usr/local/lib/python2.7/subprocess.py", line 989, in _execute_child
    preexec_fn()
  File "/usr/local/lib/python2.7/subprocess.py", line 394, in __init__
    errread, errwrite)
  File "mtfork.py", line 15, in run_command
    stdout=arg_stdout, stderr=arg_stderr, shell=True)
  File "mtfork.py", line 51, in _readerthread3
    status = run_command("/root/exe",preexec_fn=preexec_fn_no_args)
  File "/usr/local/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/local/lib/python2.7/threading.py", line 774, in __bootstrap
    self.__bootstrap_inner()
(gdb) py-list
 926                # The first char specifies the exception type: 0 means
 927                # OSError, 1 means some other error.
 928                errpipe_read, errpipe_write = self.pipe_cloexec()
 929                try:
 930                    try:
>931                        with self._disabling_gc_lock:
 932                            gc_was_enabled = gc.isenabled()
 933                            # Disable gc to avoid bug where gc -> file_dealloc ->
 934                            # write to stderr -> hang.
 935                            # https://bugs.python.org/issue1336
 936                            gc.disable()
History
Date User Action Args
2019-10-24 07:38:39Zhipeng Xiesetrecipients: + Zhipeng Xie
2019-10-24 07:38:39Zhipeng Xiesetmessageid: <1571902719.3.0.191965904237.issue38575@roundup.psfhosted.org>
2019-10-24 07:38:39Zhipeng Xielinkissue38575 messages
2019-10-24 07:38:39Zhipeng Xiecreate