diff options
author | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-27 02:01:10 +0100 |
---|---|---|
committer | Giampaolo Rodola <g.rodola@gmail.com> | 2019-02-27 02:01:10 +0100 |
commit | a5d179e0d97eeeb8112ca2bf72f846bd1ca2b161 (patch) | |
tree | c4129c6aec1f2ab8194df445321fa0ebc2a5ca2b /psutil/_pssunos.py | |
parent | d4d896512d01c7c14a4c145232e1c6bb6f4c3631 (diff) | |
download | psutil-a5d179e0d97eeeb8112ca2bf72f846bd1ca2b161.tar.gz |
_assert_alive() refactor (linux)
Diffstat (limited to 'psutil/_pssunos.py')
-rw-r--r-- | psutil/_pssunos.py | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/psutil/_pssunos.py b/psutil/_pssunos.py index faadecfe..17469eac 100644 --- a/psutil/_pssunos.py +++ b/psutil/_pssunos.py @@ -380,6 +380,12 @@ class Process(object): self._ppid = None self._procfs_path = get_procfs_path() + def _assert_alive(self): + """Raise NSP if the process disappeared on us.""" + # For those C function who do not raise NSP, possibly returning + # incorrect or incomplete result. + os.stat('%s/%s' % (self._procfs_path, self.pid)) + def oneshot_enter(self): self._proc_name_and_args.cache_activate(self) self._proc_basic_info.cache_activate(self) @@ -522,8 +528,7 @@ class Process(object): continue raise if hit_enoent: - # raise NSP if the process disappeared on us - os.stat('%s/%s' % (procfs_path, self.pid)) + self._assert_alive() @wrap_exceptions def cwd(self): @@ -585,8 +590,7 @@ class Process(object): nt = _common.pthread(tid, utime, stime) ret.append(nt) if hit_enoent: - # raise NSP if the process disappeared on us - os.stat('%s/%s' % (procfs_path, self.pid)) + self._assert_alive() return ret @wrap_exceptions @@ -610,8 +614,7 @@ class Process(object): if isfile_strict(file): retlist.append(_common.popenfile(file, int(fd))) if hit_enoent: - # raise NSP if the process disappeared on us - os.stat('%s/%s' % (procfs_path, self.pid)) + self._assert_alive() return retlist def _get_unix_sockets(self, pid): @@ -711,8 +714,7 @@ class Process(object): raise retlist.append((addr, perm, name, rss, anon, locked)) if hit_enoent: - # raise NSP if the process disappeared on us - os.stat('%s/%s' % (procfs_path, self.pid)) + self._assert_alive() return retlist @wrap_exceptions |