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

Ignore psutil exceptions in _find_agent. #203

Merged
merged 1 commit into from
Jul 25, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions gnupg/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,21 @@ def _find_agent(cls):
identity = this_process.uids

for proc in psutil.process_iter():
# In my system proc.name & proc.is_running are methods
if (proc.name() == "gpg-agent") and proc.is_running():
log.debug("Found gpg-agent process with pid %d" % proc.pid)
if _util._running_windows:
if proc.username() == identity:
ownership_match = True
else:
# proc.uids & identity are methods to
if proc.uids() == identity():
ownership_match = True
try:
# In my system proc.name & proc.is_running are methods
if (proc.name() == "gpg-agent") and proc.is_running():
log.debug("Found gpg-agent process with pid %d" % proc.pid)
if _util._running_windows:
if proc.username() == identity:
ownership_match = True
else:
# proc.uids & identity are methods to
if proc.uids() == identity():
ownership_match = True
except psutil.Error:
# Exception when getting proc info, possibly because the
# process is zombie / process no longer exist. Just ignore it.
pass
Copy link
Owner

Choose a reason for hiding this comment

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

I think I'd prefer to log when these errors occur, just in case, so that it doesn't silently cause something else to fail in some edge case in the future. I'm happy to make that change myself after merging your patch.

# Next code must be inside for operator.
# Otherwise to _agent_proc will be saved not "gpg-agent" process buth an other.
if ownership_match:
Expand Down