bpo-34663: Add support for POSIX_SPAWN_USEVFORK in posix_spawn when available#9271
bpo-34663: Add support for POSIX_SPAWN_USEVFORK in posix_spawn when available#9271pablogsal wants to merge 6 commits intopython:masterfrom
Conversation
404e2d5 to
2fe1089
Compare
| all_flags |= POSIX_SPAWN_SETSCHEDULER; | ||
| #else | ||
| PyErr_SetString(PyExc_NotImplementedError, | ||
| "The UseVFork option is not supported in this system."); |
There was a problem hiding this comment.
The parameter is called "usevfork", the error message should use the same name (not "UseVFork").
| The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag. | ||
| scheduler: object = NULL | ||
| A tuple with the scheduler policy (optional) and parameters. | ||
| usevfork: bool(accept={int}) = False |
There was a problem hiding this comment.
I suggest the name "use_vfork", or maybe even "vfork".
|
When you're done making the requested changes, leave the comment: |
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
b67b99d to
e72c246
Compare
| #ifdef POSIX_SPAWN_USEVFORK | ||
| all_flags |= POSIX_SPAWN_SETSCHEDULER; | ||
| #else | ||
| PyErr_SetString(PyExc_NotImplementedError, |
There was a problem hiding this comment.
You can use argument_unavailable_error() here.
There was a problem hiding this comment.
I discussed with Pablo and using "posix_spawn()" function name is less useless than mentioning the "POSIX_SPAWN_USEVFORK flag".
| scheduler: object = NULL | ||
| A tuple with the scheduler policy (optional) and parameters. | ||
| use_vfork: bool(accept={int}) = False | ||
| If the value is `True` the POSIX_SPAWN_USEVFORK will be activated. |
There was a problem hiding this comment.
"If the value is true": use_vfork=1 should be equivalent to use_vfork=True.
|
|
||
| def test_vfork(self): | ||
| try: | ||
| pid = posix.posix_spawn( |
There was a problem hiding this comment.
You might use args = self.python_args() and posix.posix_spawn(args[0], args, ...)
|
Please also document the use_vfork parameter in Doc/library/os.html |
8bad285 to
2fe9bf1
Compare
| If the value of *use_vfork* is true, the child will be created using | ||
| :c:func:`vfork` instead of :c:func:`fork`. This corresponds to the | ||
| GNU specific flag :c:data:`POSIX_SPAWN_USEVFORK`. | ||
|
|
There was a problem hiding this comment.
Oh, "Availability: ..." is missing: this function is not available on Windows, right?
I would suggest to document in "Availability: ..." that the flag is only available on Linux.
|
|
||
| If the value of *use_vfork* is true, the child will be created using | ||
| :c:func:`vfork` instead of :c:func:`fork`. This corresponds to the | ||
| GNU specific flag :c:data:`POSIX_SPAWN_USEVFORK`. |
There was a problem hiding this comment.
You should document that the function raises an exception if the flag is unavailable on the platform.
| use_vfork=True | ||
| ) | ||
| except NotImplementedError: | ||
| unittest.SkipTest("POSIX_SPAWN_USEVFORK not available on this system") |
There was a problem hiding this comment.
Hum, you can just reuse the exception message as part of this error message.
| @@ -0,0 +1,2 @@ | |||
| Added support for `usevfork` parameters of `posix_spawn`, which allows to | |||
There was a problem hiding this comment.
use_vfork with underscore, no?
posix_spawn can be written :func:os.posix_spawn to get a link to the function in the generated doc.
|
When you're done making the requested changes, leave the comment: |
71f1afa to
9c14de2
Compare
9c14de2 to
70db5e9
Compare
|
I have made the requested changes; please review again |
|
Thanks for making the requested changes! @vstinner: please review the changes made to this pull request. |
| GNU specific flag :c:data:`POSIX_SPAWN_USEVFORK`. If the flag is not | ||
| available on the platform, :exc:`NotImplementedError` will be raised. | ||
|
|
||
| Availability: Using *use_vfork* is only available on Linux. |
There was a problem hiding this comment.
You should document that the function is only available on Unix. Example:
https://docs.python.org/dev/library/os.html#os.fork
| ) | ||
| except NotImplementedError: | ||
| unittest.SkipTest("POSIX_SPAWN_USEVFORK not available on this system") | ||
| except NotImplementedError as e: |
There was a problem hiding this comment.
nitpick: i prefer to avoid single character variable, i suggest the name "exc".
| except NotImplementedError: | ||
| unittest.SkipTest("POSIX_SPAWN_USEVFORK not available on this system") | ||
| except NotImplementedError as e: | ||
| raise unittest.SkipTest(e) |
There was a problem hiding this comment.
You can use: raise self.skipTest(str(exc)).
| #ifdef POSIX_SPAWN_USEVFORK | ||
| all_flags |= POSIX_SPAWN_SETSCHEDULER; | ||
| #else | ||
| PyErr_SetString(PyExc_NotImplementedError, |
There was a problem hiding this comment.
I discussed with Pablo and using "posix_spawn()" function name is less useless than mentioning the "POSIX_SPAWN_USEVFORK flag".
vstinner
left a comment
There was a problem hiding this comment.
LGTM.
@gpshead: Would you mind to double check this PR?
@benjaminp: Would you be interested to have a look as well? (the plan is then to experiment to use it in subprocess for performance.)
https://bugs.python.org/issue34663