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

fix(process): fix the bug that the program is hung when getting the f… #1182

Merged
merged 3 commits into from Nov 20, 2021
Merged

fix(process): fix the bug that the program is hung when getting the f… #1182

merged 3 commits into from Nov 20, 2021

Conversation

kestrelcjx
Copy link
Contributor

@kestrelcjx kestrelcjx commented Nov 20, 2021

psutil(https://psutil.readthedocs.io/en/latest/index.html?highlight=oepn_files#psutil.Process.open_files): Warning on Windows this method is not reliable due to some limitations of the underlying Windows API which may hang when retrieving certain file handles. In order to work around that psutil spawns a thread to determine the file handle name and kills it if it’s not responding after 100ms. That implies that this method on Windows is not guaranteed to enumerate all regular file handles (see issue 597). Tools like ProcessHacker has the same limitation.

I tried it, and when I called the OpenFile method to the graphics driver, the program was suspended. So, I use the same method as psutil to deal with it.

Copy link
Owner

@shirou shirou left a comment

Choose a reason for hiding this comment

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

Thank you for your cool PR! These changes looks good to me.

How about to add "case <- ctx.Done()" in select ? It may takes a time if many processes exists. Canceable by context is better in this situation, I think.

Copy link
Owner

@shirou shirou left a comment

Choose a reason for hiding this comment

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

Thank you for the quick update! it looks great and I have confirmed it works on my environment.

@shirou shirou merged commit de385f5 into shirou:master Nov 20, 2021
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.

None yet

2 participants