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 safe from deadlocks #59077

Closed
techtonik mannequin opened this issue May 21, 2012 · 6 comments
Closed

subprocess is not safe from deadlocks #59077

techtonik mannequin opened this issue May 21, 2012 · 6 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@techtonik
Copy link
Mannequin

techtonik mannequin commented May 21, 2012

BPO 14872
Superseder
  • bpo-1260171: subprocess: more general (non-buffering) communication
  • 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 2012-05-22.08:45:11.601>
    created_at = <Date 2012-05-21.20:33:12.583>
    labels = ['type-feature', 'library']
    title = 'subprocess is not safe from deadlocks'
    updated_at = <Date 2012-05-22.08:45:11.600>
    user = 'https://bugs.python.org/techtonik'

    bugs.python.org fields:

    activity = <Date 2012-05-22.08:45:11.600>
    actor = 'rosslagerwall'
    assignee = 'none'
    closed = True
    closed_date = <Date 2012-05-22.08:45:11.601>
    closer = 'rosslagerwall'
    components = ['Library (Lib)']
    creation = <Date 2012-05-21.20:33:12.583>
    creator = 'techtonik'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 14872
    keywords = []
    message_count = 6.0
    messages = ['161294', '161303', '161312', '161322', '161325', '161337']
    nosy_count = 5.0
    nosy_names = ['techtonik', 'cvrebert', 'rosslagerwall', 'sbt', 'weirdink13']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '1260171'
    type = 'enhancement'
    url = 'https://bugs.python.org/issue14872'
    versions = ['Python 2.7', 'Python 3.3']

    @techtonik
    Copy link
    Mannequin Author

    techtonik mannequin commented May 21, 2012

    There is no way to write a program in Python capable to process large/unlimited output coming from a subprocess stream without deadlocks.

    http://docs.python.org/library/subprocess.html#subprocess.Popen.communicate
    "Note The data read is buffered in memory, so do not use this method if the data size is large or unlimited."

    http://docs.python.org/library/subprocess.html#subprocess.Popen.stdin
    http://docs.python.org/library/subprocess.html#subprocess.Popen.stdout
    http://docs.python.org/library/subprocess.html#subprocess.Popen.stderr
    "Warning Use communicate() rather than .stdin.write, .stdout.read or .stderr.read to avoid deadlocks due to any of the other OS pipe buffers filling up and blocking the child process."

    So, what should I use?

    @techtonik techtonik mannequin added the stdlib Python modules in the Lib dir label May 21, 2012
    @sbt
    Copy link
    Mannequin

    sbt mannequin commented May 21, 2012

    I think the note for communicate() just means that you might get MemoryError (or some other exception) if the output is too big. But I agree it is ambiguous.

    communicate() uses select() on Unix and threads on Windows, so deadlocks should not be possible.

    So, what should I use?

    Use communicate() (on a machine with infinite memory;-)

    @weirdink13
    Copy link
    Mannequin

    weirdink13 mannequin commented May 22, 2012

    what sort of machine has infinite memory?

    @rosslagerwall
    Copy link
    Mannequin

    rosslagerwall mannequin commented May 22, 2012

    Well if you're *certain* that the process is only using one stream, then you can just use read/write on that stream.

    If not, it probably means you have to use either threads or select/poll.

    This is a known issue with subprocess; there are a few proposals on the tracker about this. See bpo-1191964 for example.

    @techtonik
    Copy link
    Mannequin Author

    techtonik mannequin commented May 22, 2012

    The problem with memory is more actual for machines with SSD where swap is usually turned off and /tmp files are located on memory disk. Hitting memory limit often means hard reset.

    My process is pretty generic that uses all streams, and I don't know how to use threads/polls crossplatform way.

    bpo-1191964 looks interesting.

    @rosslagerwall
    Copy link
    Mannequin

    rosslagerwall mannequin commented May 22, 2012

    See also bpo-1260171.

    Closing as a duplicate of that.

    @rosslagerwall rosslagerwall mannequin closed this as completed May 22, 2012
    @rosslagerwall rosslagerwall mannequin added the type-feature A feature request or enhancement label May 22, 2012
    @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-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants