Issue 17824: pty.spawn handles errors improperly (original) (raw)

Created on 2013-04-24 02:59 by niemeyer, last changed 2022-04-11 14:57 by admin.

Messages (4)
msg187681 - (view) Author: Gustavo Niemeyer (niemeyer) * (Python committer) Date: 2013-04-24 02:59
This simple script will spawn N Python interpreters that aren't properly collected due to the improper error handling: import pty for i in range(N): try: pty.spawn(["/non-existent"]) except: pass
msg228264 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-10-02 22:09
Can a linux guru comment on this please.
msg252445 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-10-07 02:20
The spawn() function has this code outside of any error handler: pid, master_fd = fork() if pid == CHILD: os.execlp(argv[0], *argv) If fork() succeeds, there will actually be a parent Python process and a child Python process. If exec() then fails, an exception will escape the spawn() function in the child process, while the parent process will carry on as if all is well. Maybe it would be worthwhile studying how the “subprocess” module handles exec() failure in the child process.
msg285300 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-01-12 10:48
The patch for Issue 26228 proposes an improvement to the situation, although it is not perfect and does not include a test. I wonder if it is possible to replace fork() and execlp() with a subprocess.Popen invokation, at least in a new Python release?
History
Date User Action Args
2022-04-11 14:57:44 admin set github: 62024
2017-01-12 21:01:10 BreamoreBoy set nosy: - BreamoreBoy
2017-01-12 10:48:45 martin.panter set messages: +
2015-10-07 02:20:17 martin.panter set nosy: + martin.pantermessages: + stage: needs patch
2014-10-02 22:09:38 BreamoreBoy set nosy: + BreamoreBoymessages: + versions: + Python 2.7, Python 3.4, Python 3.5, - Python 3.3
2013-04-24 02:59:30 niemeyer create