-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-31884 subprocess set priority on windows #4150
Conversation
adds the required constants that can be passed to creationflags for Popen to allow setting the process priority on windows.
Update subprocess.py
add constants for setting process priority
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
You could also add the following creation flags:
The new constants should be documented in section "5.4.1. Constants", with a note about what was added in 3.7. |
Makes sense, however i thought it was already possible to allocate a console without a window via the startupinfo argument? |
When a console application initializes (i.e. the entry point of kernelbase.dll), if it doesn't inherit a console (i.e. a connection handle for an instance of conhost.exe), it allocates a new console and uses the process Use the creation flag Use An issue with using It's an error to specify both |
thanks for the thorough explanation, i didn't realize the nuanced combinations of flags that are possible with this API and the effects this has for further child processes, i'll add to the pull request with these new flags and documentation. |
added: CREATE_NO_WINDOW (allocate a console without a window) DETACHED_PROCESS (do not inherit or allocate a console) CREATE_DEFAULT_ERROR_MODE CREATE_BREAKAWAY_FROM_JOB
CREATE_NO_WINDOW (allocate a console without a window) DETACHED_PROCESS (do not inherit or allocate a console) CREATE_DEFAULT_ERROR_MODE CREATE_BREAKAWAY_FROM_JOB
@eryksun can you clarify where the documentation needs to be ammended? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to document these constants in the "Constants" section of Doc/library/subprocess.rst.
You have to add ".. versionadded:: 3.7" in the doc of added constants. Maybe add a subsection for Windows priority constants?
test_subprocess fails on Windows (see AppVeyor):
|
Doc/library/subprocess.rst
Outdated
:data:`CREATE_NO_WINDOW` | ||
:data:`DETACHED_PROCESS` | ||
:data:`CREATE_DEFAULT_ERROR_MODE` | ||
:data:`CREATE_BREAKAWAY_FROM_JOB` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this "versioadded" section. I suggest to remove it.
Doc/library/subprocess.rst
Outdated
.. data:: ABOVE_NORMAL_PRIORITY_CLASS | ||
|
||
A :class:`Popen` ``creationflags`` parameter to specify that a new process | ||
will have an above average priority. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have to add ".. versionadded:: 3.7" here: same for each added constant below.
Doc/library/subprocess.rst
Outdated
.. data:: CREATE_BREAKAWAY_FROM_JOB | ||
|
||
A :class:`Popen` ``creationflags`` parameter to specify that a new process | ||
is not associated with the job. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add an empty line.
Doc/library/subprocess.rst
Outdated
@@ -516,8 +516,24 @@ functions. | |||
|
|||
If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is | |||
passed to the underlying ``CreateProcess`` function. | |||
*creationflags*, if given, can be :data:`CREATE_NEW_CONSOLE` or | |||
:data:`CREATE_NEW_PROCESS_GROUP`. (Windows only) | |||
*creationflags*, if given, can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems unrelated and I preferred the previous formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm not sure how this is unrelated? this shows where the added constants should be used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, when I wrote my comment, the doc was formatted differently.
Ok, now I suggest to format these constants as a list:
* a
* b
* c
* ...
(correctly indented for the current section)
Try to build the documentation to see how it's rendered in HTML. On Unix, it's "make -C Doc html". I don't know how to build it on Windows :-(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately i don't currently have access to a unix box (windows 10 broke my dual boot) and currently on a work pc so don't even have git client, doing this through the web interface... so i can't build the docs to see how they look
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creationflags, if given, can be
I checked in MSDN: in fact, you can specify multiple flags at once:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
dwFlags: "A bitfield that determines whether certain STARTUPINFO members are used when the process creates a window. This member can be one or more of the following values."
By the way, please add a column after "can be" ("can be:"), and an empty line after.
I propose: "can be one or more of the following flags:".
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Doc/library/subprocess.rst
Outdated
|
||
.. data:: ABOVE_NORMAL_PRIORITY_CLASS | ||
|
||
.. versionadded:: 3.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The versionadded markup is usually added after the text, and surrounded by an empty line (above and after).
Doc/library/subprocess.rst
Outdated
The new process has a new console, instead of inheriting its parent's | ||
console (the default). | ||
|
||
.. data:: CREATE_NEW_PROCESS_GROUP | ||
|
||
|
||
.. versionadded:: 3.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems wrong: this constant was already available on Python 3.6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. The overall change looks good to me, but I still have a few comments on the documentation which can be enhanced.
Doc/library/subprocess.rst
Outdated
@@ -843,6 +855,8 @@ The :mod:`subprocess` module exposes the following constants. | |||
The new process has a new console, instead of inheriting its parent's | |||
console (the default). | |||
|
|||
.. versionadded:: 3.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's wrong: the flag already existed in Python 3.6.
Doc/library/subprocess.rst
Outdated
@@ -851,6 +865,86 @@ The :mod:`subprocess` module exposes the following constants. | |||
|
|||
This flag is ignored if :data:`CREATE_NEW_CONSOLE` is specified. | |||
|
|||
.. versionadded:: 3.7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's wrong: the flag already existed in Python 3.6.
Doc/library/subprocess.rst
Outdated
* :data:`DETACHED_PROCESS` | ||
* :data:`CREATE_DEFAULT_ERROR_MODE` | ||
* :data:`CREATE_BREAKAWAY_FROM_JOB` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A single empty line is enough at the end of this list.
Doc/library/subprocess.rst
Outdated
@@ -843,6 +855,8 @@ The :mod:`subprocess` module exposes the following constants. | |||
The new process has a new console, instead of inheriting its parent's |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The title of the current section is " Constants". I checked: all constants documented here as specific to Windows. I propose to rename the section to "Windows Constants". Can you please do that?
Doc/library/subprocess.rst
Outdated
@@ -516,8 +516,24 @@ functions. | |||
|
|||
If given, *startupinfo* will be a :class:`STARTUPINFO` object, which is | |||
passed to the underlying ``CreateProcess`` function. | |||
*creationflags*, if given, can be :data:`CREATE_NEW_CONSOLE` or | |||
:data:`CREATE_NEW_PROCESS_GROUP`. (Windows only) | |||
*creationflags*, if given, can be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
creationflags, if given, can be
I checked in MSDN: in fact, you can specify multiple flags at once:
https://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
dwFlags: "A bitfield that determines whether certain STARTUPINFO members are used when the process creates a window. This member can be one or more of the following values."
By the way, please add a column after "can be" ("can be:"), and an empty line after.
I propose: "can be one or more of the following flags:".
The doc job of Travis CI failed with:
Please remove also these trailing spaces ;-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you for all updates! And I'm sorry for being so much pedantic about this PR ;-)
@zooba: Nice, subprocess now will get the constants that you used in https://github.com/haypo/perf to set the priority ;-) |
i don't mind the being pedantic, its my first time contributing to a project this structured, but i wouldn't have it any other way. there is a reason that pythons docs are comprehensive and useful... |
PR merged, thank again ;-) I changed the commit title. |
adds the required constants for setting process priority to the _winapi module
imports and makes available those constants in the subprocessing module
https://bugs.python.org/issue31884