Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pty.spawn handles errors improperly #62024

Open
niemeyer mannequin opened this issue Apr 24, 2013 · 4 comments
Open

pty.spawn handles errors improperly #62024

niemeyer mannequin opened this issue Apr 24, 2013 · 4 comments
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@niemeyer
Copy link
Mannequin

niemeyer mannequin commented Apr 24, 2013

BPO 17824
Nosy @vadmium

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2013-04-24.02:59:30.099>
labels = ['type-bug', 'library']
title = 'pty.spawn handles errors improperly'
updated_at = <Date 2017-01-12.21:01:10.088>
user = 'https://bugs.python.org/niemeyer'

bugs.python.org fields:

activity = <Date 2017-01-12.21:01:10.088>
actor = 'BreamoreBoy'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2013-04-24.02:59:30.099>
creator = 'niemeyer'
dependencies = []
files = []
hgrepos = []
issue_num = 17824
keywords = []
message_count = 4.0
messages = ['187681', '228264', '252445', '285300']
nosy_count = 2.0
nosy_names = ['niemeyer', 'martin.panter']
pr_nums = []
priority = 'normal'
resolution = None
stage = 'needs patch'
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue17824'
versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

@niemeyer
Copy link
Mannequin Author

niemeyer mannequin commented Apr 24, 2013

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

@niemeyer niemeyer mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Apr 24, 2013
@BreamoreBoy
Copy link
Mannequin

BreamoreBoy mannequin commented Oct 2, 2014

Can a linux guru comment on this please.

@vadmium
Copy link
Member

vadmium commented Oct 7, 2015

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.

@vadmium
Copy link
Member

vadmium commented Jan 12, 2017

The patch for bpo-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?

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant