FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-35537: subprocess uses os.posix_spawn in some cases by vstinner · Pull Request #11452 · python/cpython · GitHub

/ cpython Public

bpo-35537: subprocess uses os.posix_spawn in some cases - #11452

Merged
vstinner merged 5 commits into
python:masterfrom
vstinner:subprocess_spawn
Jan 15, 2019
Merged

bpo-35537: subprocess uses os.posix_spawn in some cases#11452
vstinner merged 5 commits into
python:masterfrom
vstinner:subprocess_spawn

Conversation

vstinner commented Jan 7, 2019
edited by bedevere-bot
Loading

Copy link
Copy Markdown
Member

subprocess.Popen now uses os.posix_spawn() in some cases, if:

  • os.posix_spawn() is available and properly reports errors to the
    parent process: macOS or glibc 2.26 and newer (or glibc 2.24 and
    newer on Linux).
  • executable path contains a directory
  • close_fds=False
  • preexec_fn, pass_fds, cwd, stdin, stdout, stderr
    and start_new_session parameters are not set

https://bugs.python.org/issue35537

subprocess.Popen now uses os.posix_spawn() in some cases, if:

* os.posix_spawn() is available and properly reports errors to the
  parent process: macOS or glibc 2.26 and newer (or glibc 2.24 and
  newer on Linux).
* executable path contains a directory
* close_fds=False
* preexec_fn, pass_fds, cwd, stdin, stdout, stderr
  and start_new_session parameters are not set

Copy link
Copy Markdown
Member Author

executable path contains a directory

Expose os.posix_spawnp() https://bugs.python.org/issue35674 will allow to remove this restriction.

Copy link
Copy Markdown
Member Author

@pablogsal, @gpshead; @izbyshev, @serhiy-storchaka: Would you mind to review this PR?

Comment thread Lib/subprocess.py Outdated
if libc == 'glibc' and version >= (2, 26):
# glibc 2.26 added a pipe to the POSIX implementation
# of posix_spawn() to properly report errors to the parent process.
return True

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Note that the patch that added a pipe to the POSIX implementation also switched to unconditional use of fork. Since the main motivation for using posix_spawn appears to be performance benefits of vfork, it seems that glibc's POSIX implementation shouldn't be used at all. I suggest to remove this branch.

Otherwise, LGTM.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah. I didn't require to use vfork. But ok, I modified my PR to prefer posix_spawn() implementations which can use vfork in some cases for best performances. Let's start with a minimum platform support, and extend it later.

vstinner commented Jan 14, 2019 via email

Copy link
Copy Markdown
Member Author

Copy link
Copy Markdown
Contributor

I meant the POSIX implementation (in sysdeps/posix/spawni.c), not the Linux one (in sysdeps/unix/sysv/linux/spawni.c) which uses clone(CLONE_VM|CLONE_VFORK) and is probably used on your laptop. In my understanding, you check for the POSIX one in glibc 2.26 branch and for the Linux one in glibc 2.24 branch.

Copy link
Copy Markdown
Member Author

@giampaolo: Would you mind to review this change?

giampaolo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I can't comment on the usage of posix_spawn per-se (I wasn't aware it existed). The only comment I can provide is that I took a look at the discussion in bpo-35537 and the rationale seems to make sense (quite consistent speedup, nice one!). IMHO assuming using posix_spawn is safe, the patch as-is LGTM and considering the gain it makes sense to take the risk.

Nitpick: perhaps it would be good to include the benchmark results in whatsnew.

Copy link
Copy Markdown
Member Author

IMHO assuming using posix_spawn is safe, the patch as-is LGTM and considering the gain it makes sense to take the risk.

Honestly, I'm not 100% sure that the change is safe. But I want to make it because of the nice speedup. I prefer to push the change early during Python 3.8 devcycle, so if someone spot an issue, we have time to try to fix it, or just revert the change.

Nitpick: perhaps it would be good to include the benchmark results in whatsnew.

@serhiy-storchaka asked to not write it, at least not announce a generic "60x speedup":
#11242 (comment)

Moreover, the speedup is only enabled under very specific conditions (see the long list of conditions in my What's New in Python 3.8 entry). We can run more benchmarks later to have a better idea of the "average speedup", and so document the speedup.

vstinner merged commit 9daecf3 into python:master Jan 15, 2019
vstinner deleted the subprocess_spawn branch January 15, 2019 23:02

Copy link
Copy Markdown
Member Author

Follow-up (support pipes): PR #11575.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL