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

subprocess is not thread-safe #45577

Closed
kjddudaorg mannequin opened this issue Oct 4, 2007 · 2 comments
Closed

subprocess is not thread-safe #45577

kjddudaorg mannequin opened this issue Oct 4, 2007 · 2 comments
Labels
stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@kjddudaorg
Copy link
Mannequin

kjddudaorg mannequin commented Oct 4, 2007

BPO 1236
Nosy @gvanrossum
Superseder
  • bpo-1731717: race condition in subprocess module
  • 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 = <Date 2007-10-05.18:32:05.611>
    created_at = <Date 2007-10-04.21:31:57.630>
    labels = ['library', 'type-crash']
    title = 'subprocess is not thread-safe'
    updated_at = <Date 2010-11-08.16:26:07.710>
    user = 'https://bugs.python.org/kjddudaorg'

    bugs.python.org fields:

    activity = <Date 2010-11-08.16:26:07.710>
    actor = 'Chris.Gerhard'
    assignee = 'none'
    closed = True
    closed_date = <Date 2007-10-05.18:32:05.611>
    closer = 'gvanrossum'
    components = ['Library (Lib)']
    creation = <Date 2007-10-04.21:31:57.630>
    creator = 'kjd@duda.org'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 1236
    keywords = []
    message_count = 2.0
    messages = ['56230', '56246']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'kjd@duda.org', 'Chris.Gerhard']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = None
    status = 'closed'
    superseder = '1731717'
    type = 'crash'
    url = 'https://bugs.python.org/issue1236'
    versions = ['Python 2.5']

    @kjddudaorg
    Copy link
    Mannequin Author

    kjddudaorg mannequin commented Oct 4, 2007

    The following test program crashes:

    ========================================

    import threading, sys, subprocess

    # subprocess._cleanup = lambda: None

    def doit():
       for i in xrange(0, 1000):
          p = subprocess.Popen( "true" )
          p.wait()
    
    t = threading.Thread( target=doit )
    t.start()
    doit()

    ==============================

    It crashes because when one thread calls subprocess.Popen(), subprocess
    calls this _cleanup() function, which might reap the subprocess started
    in another thread ! The other thread might be inside
    subprocess.Popen.wait(), just about to call waitpid(), and kill itself.

    If you uncomment the commented line, then the program runs with no problems.

    I imagine the purpose of _cleanup is to protect users from themselves,
    i.e., protect a user who calls subprocess.Popen() a lot without ever
    calling wait(). I suggest either:

    (1) eliminating this _cleanup() mechanism completely; people who do
    not wait() deserve the zombies they get;
    (2) synchronizing _cleanup() with wait() through a lock; or,
    (3) having wait() simply retry if it gets ECHILD. On the retry, it
    will discover that returncode is set, and return normally.

    -Ken

    @kjddudaorg kjddudaorg mannequin added stdlib Python modules in the Lib dir type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 4, 2007
    @gvanrossum
    Copy link
    Member

    This is a duplicate of bug# 1731717.

    I asked Donovan Baarda, who told me:

    """
    Last time I looked this had been fixed, admittedly in a bit of an ugly
    way, on the svn head. I offered to do a patch to make it a bit cleaner,
    but as it isn't really broken anymore it was a bit of a low priority and
    I haven't done it.

    This bug seems to have a good repeatable test-case that we can probably
    use in the unittests to show that it's now fixed...
    """

    @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-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant