Skip to content
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

gh-116195: Implement win32_getppid_fast #116205

Merged
merged 11 commits into from Mar 14, 2024
Merged

gh-116195: Implement win32_getppid_fast #116205

merged 11 commits into from Mar 14, 2024

Conversation

vxiiduu
Copy link
Contributor

@vxiiduu vxiiduu commented Mar 1, 2024

win32_getppid has been supplemented with win32_getppid_fast which is more efficient.

Use the NtQueryInformationProcess system call to efficiently retrieve the parent process ID in a single step, rather than using the process snapshots API which retrieves large amounts of unnecessary information and is more prone to failure (since it makes heap allocations).
@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@@ -9115,16 +9115,104 @@ os_setpgrp_impl(PyObject *module)
#ifdef HAVE_GETPPID

#ifdef MS_WINDOWS
#include <processsnapshot.h>
Copy link
Member

Choose a reason for hiding this comment

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

I think this header file is still required because we are using PssCaptureSnapshot bellow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed it is - missed that. Is there a way I can add commits to the PR without making a new one? On other repos just committing to my own branch worked.

Copy link
Member

Choose a reason for hiding this comment

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

You can just add new commit to your branch, and this PR will be updated. Close a PR and create new one will make the review work harder.

@vxiiduu vxiiduu closed this Mar 1, 2024
Modules/posixmodule.c Outdated Show resolved Hide resolved
@@ -9115,16 +9115,104 @@ os_setpgrp_impl(PyObject *module)
#ifdef HAVE_GETPPID

#ifdef MS_WINDOWS
#include <processsnapshot.h>
Copy link
Member

Choose a reason for hiding this comment

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

You can just add new commit to your branch, and this PR will be updated. Close a PR and create new one will make the review work harder.

@vxiiduu vxiiduu reopened this Mar 1, 2024
@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

1 similar comment
@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Co-authored-by: AN Long <aisk@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 1, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@aisk
Copy link
Member

aisk commented Mar 3, 2024

I see this PR is using the CamelCase naming convention for local variables, like CachedParentProcessId and Ntdll. Although this is not described in PEP 7, most of the Windows part of this file uses the snake_case naming convention for local variables. I think we should keep them consistent.

But I don't find any requirements for the naming convention, so I'm not confident about this. That is to say, if you want to keep them, we can wait for a core team member to make the convention clear.

@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@vxiiduu
Copy link
Contributor Author

vxiiduu commented Mar 3, 2024

I see this PR is using the CamelCase naming convention for local variables, like CachedParentProcessId and Ntdll. Although this is not described in PEP 7, most of the Windows part of this file uses the snake_case naming convention for local variables. I think we should keep them consistent.

Alright, that has been fixed.

Copy link
Member

@aisk aisk left a comment

Choose a reason for hiding this comment

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

I only have a few code style nitpicks. Additionally, this change introduces a new static mutable variable. I don't know whether we should track it in the c-analyzer folder or do some other work.

Otherwise, this LGTM. Let's wait for a core team member to continue the review process.

Modules/posixmodule.c Outdated Show resolved Hide resolved
Modules/posixmodule.c Outdated Show resolved Hide resolved
Modules/posixmodule.c Outdated Show resolved Hide resolved
Modules/posixmodule.c Outdated Show resolved Hide resolved
Co-authored-by: AN Long <aisk@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Co-authored-by: AN Long <aisk@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Co-authored-by: AN Long <aisk@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Co-authored-by: AN Long <aisk@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 3, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@aisk
Copy link
Member

aisk commented Mar 14, 2024

Current change looks good to me now.

Hi @zooba can you help us continue the review process as you have comments on the original issue?

@zooba
Copy link
Member

zooba commented Mar 14, 2024

LGTM. I think we can add a NEWS entry for this, partly because there's a slight risk of changed behaviour, and also to let @vxiiduu claim credit.

Thinking something like: Improves performance of :func:`os.getppid` by using an alternate system API when available. Contributed by <vxiiduu's choice of name here> (in the Windows category, so it doesn't need to explicitly say "on Windows")

@zooba zooba merged commit be1c808 into python:main Mar 14, 2024
33 of 34 checks passed
@zooba
Copy link
Member

zooba commented Mar 14, 2024

Thank you!

vstinner pushed a commit to vstinner/cpython that referenced this pull request Mar 20, 2024
Use the NtQueryInformationProcess system call to efficiently retrieve the parent process ID in a single step, rather than using the process snapshots API which retrieves large amounts of unnecessary information and is more prone to failure (since it makes heap allocations).

Includes a fallback to the original win32_getppid implementation in case the unstable API appears to return strange results.
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
Use the NtQueryInformationProcess system call to efficiently retrieve the parent process ID in a single step, rather than using the process snapshots API which retrieves large amounts of unnecessary information and is more prone to failure (since it makes heap allocations).

Includes a fallback to the original win32_getppid implementation in case the unstable API appears to return strange results.
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Use the NtQueryInformationProcess system call to efficiently retrieve the parent process ID in a single step, rather than using the process snapshots API which retrieves large amounts of unnecessary information and is more prone to failure (since it makes heap allocations).

Includes a fallback to the original win32_getppid implementation in case the unstable API appears to return strange results.
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.

None yet

3 participants