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: more general (non-buffering) communication #42281

Closed
ianbicking mannequin opened this issue Aug 15, 2005 · 8 comments
Closed

subprocess: more general (non-buffering) communication #42281

ianbicking mannequin opened this issue Aug 15, 2005 · 8 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@ianbicking
Copy link
Mannequin

ianbicking mannequin commented Aug 15, 2005

BPO 1260171
Nosy @birkenfeld, @gpshead, @giampaolo, @vadmium
Files
  • subprocess_communicate_alternative.py
  • 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 = 'https://github.com/gpshead'
    closed_at = <Date 2020-10-20.01:58:46.586>
    created_at = <Date 2005-08-15.19:15:12.000>
    labels = ['type-feature', 'library']
    title = 'subprocess: more general (non-buffering) communication'
    updated_at = <Date 2020-10-20.01:58:46.585>
    user = 'https://bugs.python.org/ianbicking'

    bugs.python.org fields:

    activity = <Date 2020-10-20.01:58:46.585>
    actor = 'gregory.p.smith'
    assignee = 'gregory.p.smith'
    closed = True
    closed_date = <Date 2020-10-20.01:58:46.586>
    closer = 'gregory.p.smith'
    components = ['Library (Lib)']
    creation = <Date 2005-08-15.19:15:12.000>
    creator = 'ianbicking'
    dependencies = []
    files = ['8255']
    hgrepos = []
    issue_num = 1260171
    keywords = ['patch']
    message_count = 8.0
    messages = ['54590', '54591', '54592', '54593', '161338', '222926', '245159', '379076']
    nosy_count = 8.0
    nosy_names = ['georg.brandl', 'gregory.p.smith', 'ianbicking', 'astrand', 'giampaolo.rodola', 'cvrebert', 'rosslagerwall', 'martin.panter']
    pr_nums = []
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue1260171'
    versions = ['Python 3.5']

    @ianbicking
    Copy link
    Mannequin Author

    ianbicking mannequin commented Aug 15, 2005

    Right now you can use subprocess.Popen.communicate() to
    make communication with subprocesses much easier and
    less likely to block than communicating directly with
    .stdin, .stdout, etc. However, that requires
    completely buffering the input and output.

    The functionality of communicate() (which is somewhat
    complex because of platform issues) could be made more
    general fairly easily. The current functionality of
    communicate could then be implemented in terms of that
    new method.

    I attached a function I'm using which does that for the
    posix systems (basically turning Popen's posix
    communicate into a function with some modifications).
    Replace "proc" with "self" (and give the function a
    better name) and you'd have a method.

    If patch 1175984 was accepted, then this wouldn't be
    that much of an issue:
    http://sourceforge.net/tracker/index.php?func=detail&aid=1175984&group_id=5470&atid=305470

    @ianbicking ianbicking mannequin assigned astrand Aug 15, 2005
    @ianbicking ianbicking mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 15, 2005
    @ianbicking ianbicking mannequin assigned astrand Aug 15, 2005
    @ianbicking ianbicking mannequin added stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Aug 15, 2005
    @josiahcarlson
    Copy link
    Mannequin

    josiahcarlson mannequin commented Aug 22, 2005

    Logged In: YES
    user_id=341410

    Would an asynchronous subprocess (which you would poll
    manually) be better/sufficient?

    http://python.org/sf/1191964

    @josiahcarlson
    Copy link
    Mannequin

    josiahcarlson mannequin commented Aug 22, 2005

    Logged In: YES
    user_id=341410

    Also, what you post is not a 'bug', it is a 'feature request'.

    @birkenfeld
    Copy link
    Member

    Logged In: YES
    user_id=1188172

    Reclassifying as RFE. Assigning to Peter.

    @rosslagerwall
    Copy link
    Mannequin

    rosslagerwall mannequin commented May 22, 2012

    Closed bpo-14872 as a duplicate of this.

    @rosslagerwall rosslagerwall mannequin unassigned astrand May 22, 2012
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Jul 13, 2014

    Please note the work being performed on bpo-1191964 which was first referenced in msg54591.

    @vadmium
    Copy link
    Member

    vadmium commented Jun 11, 2015

    The non-blocking read and write features proposed in bpo-1191964 wouldn’t be sufficient. Perhaps they might be useful for implementing this feature on Windows though; I’m not sure. And a non-blocking write on Posix may be slightly more efficient as well, removing the limitation of copying in chunks of PIPE_BUF bytes.

    Ian’s original patch posted here proposes a version of communicate() which accepts a file reader for the subprocess’s input, and file writers for the subprocess’s outputs. Another option could be something like my SubprocessWriter class <https://github.com/vadmium/pacman-tools/blob/9ffdd88/makeaur#L179\>. It provides a file writer interface for the caller to write to the subprocess’s input, while copying data from the subprocess’s output behind the scenes. I used it to stream a tar file, as it is written by the “tarfile” module, into a GPG subprocess to create a digital signature, while writing the output of GPG into a BytesIO buffer. Using Unix command pipeline pseudocode, it is used a bit like this:

    tarfile.open(mode="w|") | Popen("gpg") | BytesIO()

    @gpshead
    Copy link
    Member

    gpshead commented Oct 20, 2020

    since the time this was filed, subprocess has evolved a lot and third party options for child process have appeared as well as modern things like:

    https://docs.python.org/3/library/asyncio-subprocess.html (stdlib)

    https://trio.readthedocs.io/en/stable/reference-io.html?highlight=subprocess#options-for-starting-subprocesses (trio, easier async framework to use than asyncio)

    plumbing stdin/stdout/stderr data to python file-like objects from the stdlib subprocess APIs themselves is better left to third party solutions building on top of the subprocess module today.

    @gpshead gpshead closed this as completed Oct 20, 2020
    @gpshead gpshead self-assigned this Oct 20, 2020
    @gpshead gpshead closed this as completed Oct 20, 2020
    @gpshead gpshead self-assigned this Oct 20, 2020
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 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

    3 participants