Skip to content

pty.spawn handles errors improperly #62024

Open

Description

@niemeyer
mannequin
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']

Activity

  1. niemeyer commented on Apr 24, 2013

    niemeyermannequin
    MannequinAuthor

    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
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Apr 24, 2013
  3. BreamoreBoy commented on Oct 2, 2014

    BreamoreBoymannequin
    Mannequin

    Can a linux guru comment on this please.

  4. vadmium commented on Oct 7, 2015

    @vadmium
    Member

    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.

  5. vadmium commented on Jan 12, 2017

    @vadmium
    Member

    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?

  6. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions