Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #111541
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | eryk sun <eryksun@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Passing File Descriptors To Subprocesses |
| Date | Sun, 17 Jul 2016 03:00:35 +0000 |
| Lines | 51 |
| Message-ID | <mailman.52.1468724484.2307.python-list@python.org> (permalink) |
| References | <f421033d-5fa4-4d02-8c3e-dadc8b778e44@googlegroups.com> <CACL+1atgkjXMvy0+45pSXpVf0xxT7=iDpZDAMiHN0tP6XTd5rA@mail.gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Trace | news.uni-berlin.de ZuImcuJ8iJUEh6FNd9vMBgDSpkpiePqIyTorbbB5EGdA== |
| Return-Path | <eryksun@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.016 |
| X-Spam-Evidence | '*H*': 0.97; '*S*': 0.00; 'seemed': 0.07; 'example:': 0.10; 'python': 0.10; '2016': 0.16; 'descriptors': 0.16; 'exit()': 0.16; 'fcntl': 0.16; 'parent:': 0.16; 'pipes': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:File': 0.16; 'subprocess': 0.16; 'wrote:': 0.16; 'settings.': 0.18; '>>>': 0.20; 'arguments': 0.22; 'lawrence': 0.22; 'os,': 0.22; 'pass': 0.22; 'am,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'url:bugs': 0.24; 'linux': 0.26; 'message- id:@mail.gmail.com': 0.27; 'specify': 0.27; 'pep': 0.29; 'url:peps': 0.29; 'url:python': 0.33; 'flags': 0.33; 'open': 0.33; 'correctly': 0.34; 'file': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'false': 0.35; 'url:dev': 0.35; 'url:org': 0.36; 'child': 0.36; 'url:library': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'skip:o 20': 0.38; 'to:addr:python.org': 0.40; 'called': 0.40; 'url:3': 0.60; 'matter': 0.63; 'more': 0.63; 'to,': 0.63; 'mar': 0.65; 'skip:\xe2 10': 0.70; '8bit%:40': 0.72; 'jul': 0.72; '5.3.1': 0.84; 'child,': 0.84 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-transfer-encoding; bh=/gsFnMexbOYP3z4CSDgkz2hTeT6PiyTZcmDjrb5X64E=; b=sAZRh9QHPq5RSQ9f7MwjIenBxiACZ5Iha2SlFaZbNu6xS4jIgEIxWSu78lq1ar/pzd 9ElX0F0QcD+5fyvJ7EbubBMpQJOjKn5a3/Y014+Vc8CqCsBHicExBSTmvMMrIGOWrJgf e0ptOEc2lHPMgFyFQ4b61qxSCShY/8X5I9jHuu7Wew69/MXK5MIsk2zqu7X2f1zG4v6H VZ3qdVnkwEw0p4KT7hKWKVJUpjopMhppMz2hG2XFCWfLM1wOfwjOKoEXGxRuxqL6R95r CIaU98SDBuSNmSU1hdpUPP+jIdh3OlTBiVDnJzsAltHyD3SOknQCdF6+wHVhOcgdyGXx uJRQ== |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-transfer-encoding; bh=/gsFnMexbOYP3z4CSDgkz2hTeT6PiyTZcmDjrb5X64E=; b=YibS/C6q5hzXVLYI7AsEGRqiyB9ow6XcGhl4G+X51DdDXRweCTFbTc7VqMLpbw3Dzd vUjVuqO02btz3gOCek8mzapFnC4OfIJMODEgpnp1UbjJ25zxCgj2ucEZ8uP16yeLAXxT kYuBapKyrq6mTVZGFLdCtvP8KiK6ga+EGCPtCz0df/+Yz0tL8oDKxKQCz5uEX5X8NnNK oVIfrSDKbvmDfsrubU23vXA6ufmvswqBlSR5pvRKsF1XTyw9uOIHfjVrTUPovpEUZf8s xRmpDJTeCyUX1FyZktMcsLaTBcLICHltl+jl1pHc2lI7z2TYak8tvTpohjOzlfe45xxt C6gg== |
| X-Gm-Message-State | ALyK8tLn8Mw1EyPMUBrjDuFVwfqmFo0DRaLQTufYYrwTzi0DrKU02t8pzgXEyX7IifXRtw8hmd5E3jOZ8Wecdw== |
| X-Received | by 10.36.37.146 with SMTP id g140mr27969101itg.58.1468724475276; Sat, 16 Jul 2016 20:01:15 -0700 (PDT) |
| In-Reply-To | <f421033d-5fa4-4d02-8c3e-dadc8b778e44@googlegroups.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.22 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <CACL+1atgkjXMvy0+45pSXpVf0xxT7=iDpZDAMiHN0tP6XTd5rA@mail.gmail.com> |
| X-Mailman-Original-References | <f421033d-5fa4-4d02-8c3e-dadc8b778e44@googlegroups.com> |
| Xref | csiph.com comp.lang.python:111541 |
Show key headers only | View raw
On Sun, Jul 17, 2016 at 1:59 AM, Lawrence D’Oliveiro
<lawrencedo99@gmail.com> wrote:
> The various subprocess functions <https://docs.python.org/3/library/subprocess.html> have
> arguments called “close_fds” and “pass_fds”, which specify which file descriptors are to be
> left open in the child process. Yet no matter what I set these to, it seemed I could not pass
> my pipes to a subprocess.
>
> What the docs *don’t* tell you is that these arguments do not control what happens after the
> exec. The file descriptors that are kept open are only those which do not have the
> FD_CLOEXEC flags set in their fcntl settings.
It works correctly in 3.4+, which makes the pass_fds file descriptors
inheritable in the child, after fork. See issue 18571 and PEP 446,
section "Other Changes":
http://bugs.python.org/issue18571
https://www.python.org/dev/peps/pep-0446/#other-changes
For example:
Python 3.5.1+ (default, Mar 30 2016, 22:46:26)
[GCC 5.3.1 20160330] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, subprocess
>>> fdr, fdw = os.pipe()
>>> fdw
4
>>> os.get_inheritable(fdw)
False
>>> subprocess.call(['python3'], pass_fds=[fdw])
child:
Python 3.5.1+ (default, Mar 30 2016, 22:46:26)
[GCC 5.3.1 20160330] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.write(4, b'spam')
4
>>> exit()
parent:
0
>>> os.read(fdr, 4)
b'spam'
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Passing File Descriptors To Subprocesses Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-16 18:59 -0700
Re: Passing File Descriptors To Subprocesses eryk sun <eryksun@gmail.com> - 2016-07-17 03:00 +0000
Re: Passing File Descriptors To Subprocesses Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-17 00:06 -0700
csiph-web