Skip to content

bpo-34663: Add support for POSIX_SPAWN_USEVFORK in posix_spawn when available#9271

Closed
pablogsal wants to merge 6 commits intopython:masterfrom
pablogsal:usevfork_posix_spawn
Closed

bpo-34663: Add support for POSIX_SPAWN_USEVFORK in posix_spawn when available#9271
pablogsal wants to merge 6 commits intopython:masterfrom
pablogsal:usevfork_posix_spawn

Conversation

@pablogsal
Copy link
Copy Markdown
Member

@pablogsal pablogsal commented Sep 13, 2018

Comment thread Modules/posixmodule.c Outdated
all_flags |= POSIX_SPAWN_SETSCHEDULER;
#else
PyErr_SetString(PyExc_NotImplementedError,
"The UseVFork option is not supported in this system.");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The parameter is called "usevfork", the error message should use the same name (not "UseVFork").

Comment thread Modules/posixmodule.c Outdated
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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suggest the name "use_vfork", or maybe even "vfork".

@bedevere-bot
Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@pablogsal
Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link
Copy Markdown

Thanks for making the requested changes!

@vstinner: please review the changes made to this pull request.

Comment thread Modules/posixmodule.c
#ifdef POSIX_SPAWN_USEVFORK
all_flags |= POSIX_SPAWN_SETSCHEDULER;
#else
PyErr_SetString(PyExc_NotImplementedError,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use argument_unavailable_error() here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I discussed with Pablo and using "posix_spawn()" function name is less useless than mentioning the "POSIX_SPAWN_USEVFORK flag".

Comment thread Modules/posixmodule.c Outdated
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

"If the value is true": use_vfork=1 should be equivalent to use_vfork=True.

Comment thread Lib/test/test_posix.py

def test_vfork(self):
try:
pid = posix.posix_spawn(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You might use args = self.python_args() and posix.posix_spawn(args[0], args, ...)

@vstinner
Copy link
Copy Markdown
Member

Please also document the use_vfork parameter in Doc/library/os.html

Comment thread Doc/library/os.rst
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`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread Doc/library/os.rst Outdated

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`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should document that the function raises an exception if the flag is unavailable on the platform.

Comment thread Lib/test/test_posix.py Outdated
use_vfork=True
)
except NotImplementedError:
unittest.SkipTest("POSIX_SPAWN_USEVFORK not available on this system")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@bedevere-bot
Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@pablogsal pablogsal force-pushed the usevfork_posix_spawn branch 3 times, most recently from 71f1afa to 9c14de2 Compare September 13, 2018 21:38
@pablogsal
Copy link
Copy Markdown
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link
Copy Markdown

Thanks for making the requested changes!

@vstinner: please review the changes made to this pull request.

Comment thread Doc/library/os.rst Outdated
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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You should document that the function is only available on Unix. Example:
https://docs.python.org/dev/library/os.html#os.fork

Comment thread Lib/test/test_posix.py Outdated
)
except NotImplementedError:
unittest.SkipTest("POSIX_SPAWN_USEVFORK not available on this system")
except NotImplementedError as e:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nitpick: i prefer to avoid single character variable, i suggest the name "exc".

Comment thread Lib/test/test_posix.py Outdated
except NotImplementedError:
unittest.SkipTest("POSIX_SPAWN_USEVFORK not available on this system")
except NotImplementedError as e:
raise unittest.SkipTest(e)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use: raise self.skipTest(str(exc)).

Comment thread Modules/posixmodule.c
#ifdef POSIX_SPAWN_USEVFORK
all_flags |= POSIX_SPAWN_SETSCHEDULER;
#else
PyErr_SetString(PyExc_NotImplementedError,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I discussed with Pablo and using "posix_spawn()" function name is less useless than mentioning the "POSIX_SPAWN_USEVFORK flag".

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

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.)

@pablogsal pablogsal closed this Sep 20, 2018
@pablogsal pablogsal deleted the usevfork_posix_spawn branch September 20, 2018 10:50
@pablogsal pablogsal restored the usevfork_posix_spawn branch January 9, 2019 18:30
@pablogsal pablogsal deleted the usevfork_posix_spawn branch May 19, 2021 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants