classification
Title: Expose os.posix_spawnp()
Type: Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: izbyshev, nanjekyejoannah, pablogsal, serhiy.storchaka, vstinner
Priority: normal Keywords: patch, patch, patch, patch

Created on 2019-01-07 00:46 by vstinner, last changed 2019-01-16 14:34 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11545 closed python-dev, 2019-01-13 21:27
PR 11545 closed python-dev, 2019-01-13 21:27
PR 11545 closed python-dev, 2019-01-13 21:27
PR 11545 closed python-dev, 2019-01-13 21:27
PR 11554 merged nanjekyejoannah, 2019-01-14 14:10
PR 11554 merged nanjekyejoannah, 2019-01-14 14:10
PR 11554 merged nanjekyejoannah, 2019-01-14 14:10
Messages (11)
msg333128 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-07 00:46
bpo-20104 exposed os.posix_spawn(), but not os.posix_spawnp().

os.posix_spawnp() would be useful to support executable with no directory. See bpo-35537 "use os.posix_spawn in subprocess".

I'm not sure what is the best API:

* Add os.posix_spawnp()? duplicate the documentation and some parts of the C code (but share most of the C code)
* Add a new optional parameter to os.posix_spawn()? Ideas of names: 'use_path' or 'search_executable'. Internally, the glibc uses SPAWN_XFLAGS_USE_PATH flag to distinguish posix_spawn() and posix_spawnp().

execvp() uses the PATH environment variable, or use confstr(_CS_PATH) if PATH is not set. I guess that posix_spawnp() also uses confstr(_CS_PATH) if PATH is not set.

Currently, my favorite option is to add a new optional 'use_path' parameter to the existing os.posix_spawn() function.
msg333130 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-07 00:49
Historically, Python used to mimick the libc: there are os.stat() and os.lstat() for example. But later, os.stat(*, follow_symlinks=False) keyword-only parameter has been added: if true, lstat() is used internally.
msg333142 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-01-07 08:19
To add some context, the follow_symlinks parameter was added to os.stat() after adding support of *at() functions (like openat() and fstatat()). Since both C functions stat() and lstat() are superseded by fstatat(), the latter was exposed at Python level as adding new keyword-only parameters to os.stat(). This allowed to avoid significant increasing the number of functions in the os module.

Since there is no function that supersedes both posix_spawn() and posix_spawnp(), this may be an argument for exposing them as separate functions at Python level. Although this argument is not very strong.
msg333212 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-01-08 08:36
I would go with exposing  posix_spawnp() as a separate function to rule out any arguments.

I am working on this in this regard unless anyone has a different view.
msg333225 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-08 11:51
I'm ok to expose posix_spawnp() as os.posix_spawnp().

Even if we expose posix_spawnp() as os.posix_spawnp(), we can still reconsider to add posix_spawnp() feature into os.posix_spawn() as an optional keyword parameter later :-) Honestly, I have no strong preference for the API. My main problem with the keyword option is the risk of name conflict if a new feature is added to posix_spawn() with a name similar to my proposed name "use_path".
msg333346 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2019-01-09 21:55
I also think to expose posix_spawnp() as os.posix_spawnp() seems the more consistent thing to do as the os/posix module tries to mirror glibc as much as possible, which helps with discoverability and cross-reference with man pages.
msg333347 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-09 21:56
Pablo:
> I also think to expose posix_spawnp() as os.posix_spawnp() seems the more consistent thing to do as the os/posix module tries to mirror glibc as much as possible, which helps with discoverability and cross-reference with man pages.

Ok. Let's do that.

@Joannah Nanjekye: Don't hesitate to come to me if you need my help to implement that ;-)
msg333375 - (view) Author: Joannah Nanjekye (nanjekyejoannah) * (Python committer) Date: 2019-01-10 12:27
Now that there is consesus, I am working on a PR for this.
msg333767 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-16 13:29
New changeset 92b8322e7ea04b239cb1cb87b78d952f13ddfebb by Victor Stinner (Joannah Nanjekye) in branch 'master':
bpo-35674: Add os.posix_spawnp() (GH-11554)
https://github.com/python/cpython/commit/92b8322e7ea04b239cb1cb87b78d952f13ddfebb
msg333772 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-16 14:33
Well done Joannah Nanjekye :-) Thanks to Joannah for this nice enhancemenet and to all reviewers.
msg333773 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2019-01-16 14:34
FYI I modified subprocess to use os.posix_spawnp() when it's available:

New changeset 07858894689047c77f9c12ddc061d30681368d19 by Victor Stinner in branch 'master':
bpo-35537: subprocess can now use os.posix_spawnp (GH-11579)
https://github.com/python/cpython/commit/07858894689047c77f9c12ddc061d30681368d19
History
Date User Action Args
2019-01-16 14:34:00vstinnersetkeywords: patch, patch, patch, patch

messages: + msg333773
2019-01-16 14:33:10vstinnersetstatus: open -> closed
messages: + msg333772

keywords: patch, patch, patch, patch
resolution: fixed
stage: patch review -> resolved
2019-01-16 13:29:30vstinnersetmessages: + msg333767
2019-01-14 14:10:42nanjekyejoannahsetpull_requests: + pull_request11189
2019-01-14 14:10:34nanjekyejoannahsetpull_requests: + pull_request11188
2019-01-14 14:10:26nanjekyejoannahsetpull_requests: + pull_request11187
2019-01-13 21:27:47python-devsetkeywords: + patch
stage: patch review
pull_requests: + pull_request11160
2019-01-13 21:27:36python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11161
2019-01-13 21:27:26python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11159
2019-01-13 21:27:16python-devsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11158
2019-01-13 16:47:15izbyshevsetnosy: + izbyshev
2019-01-10 12:27:10nanjekyejoannahsetmessages: + msg333375
2019-01-09 21:56:30vstinnersetmessages: + msg333347
2019-01-09 21:55:38pablogsalsetmessages: + msg333346
2019-01-08 11:51:18vstinnersetmessages: + msg333225
2019-01-08 08:36:28nanjekyejoannahsetnosy: + nanjekyejoannah
messages: + msg333212
2019-01-07 08:19:15serhiy.storchakasetmessages: + msg333142
2019-01-07 00:49:10vstinnersetmessages: + msg333130
2019-01-07 00:46:08vstinnercreate