Skip to content

Commit

Permalink
fix #986: [Linux] Process.cwd() may raise NoSuchProcess instead of Zo…
Browse files Browse the repository at this point in the history
…mbieProcess.
  • Loading branch information
giampaolo committed Mar 4, 2017
1 parent 852cb32 commit 1922a76
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

- 872_: [Linux] can now compile on Linux by using MUSL C library.
- 985_: [Windows] Fix a crash in `Process.open_files` when the worker thread for `NtQueryObject` times out.
- 986_: [Linux] Process.cwd() may raise NoSuchProcess instead of ZombieProcess.

5.1.3
=====
Expand Down
11 changes: 10 additions & 1 deletion psutil/_pslinux.py
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,16 @@ def memory_maps(self):

@wrap_exceptions
def cwd(self):
return readlink("%s/%s/cwd" % (self._procfs_path, self.pid))
try:
return readlink("%s/%s/cwd" % (self._procfs_path, self.pid))
except OSError as err:
# https://github.com/giampaolo/psutil/issues/986
if err.errno in (errno.ENOENT, errno.ESRCH):
if not pid_exists(self.pid):
raise NoSuchProcess(self.pid, self._name)
else:
raise ZombieProcess(self.pid, self._name, self._ppid)
raise

@wrap_exceptions
def num_ctx_switches(self, _ctxsw_re=re.compile(b'ctxt_switches:\t(\d+)')):
Expand Down

0 comments on commit 1922a76

Please sign in to comment.