diff --git a/HISTORY.rst b/HISTORY.rst index 8c026524c..4793d3d31 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,14 @@ Bug tracker at https://github.com/giampaolo/psutil/issues -3.0.0 - XXXX-XX-XX +3.0.1 - XXXX-XX-XX +================== + +**Bug fixes** + +- #632: [Linux] better error message if cannot parse process UNIX connections. + + +3.0.0 - 2015-06-13 ================== **Enhancements** diff --git a/psutil/_pslinux.py b/psutil/_pslinux.py index 668154bb3..db96776ae 100644 --- a/psutil/_pslinux.py +++ b/psutil/_pslinux.py @@ -466,8 +466,13 @@ def process_inet(self, file, family, type_, inodes, filter_pid=None): with open(file, 'rt') as f: f.readline() # skip the first line for line in f: - _, laddr, raddr, status, _, _, _, _, _, inode = \ - line.split()[:10] + try: + _, laddr, raddr, status, _, _, _, _, _, inode = \ + line.split()[:10] + except ValueError: + raise RuntimeError( + "error while parsing %s; malformed line %r" % ( + file, line)) if inode in inodes: # # We assume inet sockets are unique, so we error # # out if there are multiple references to the @@ -495,7 +500,12 @@ def process_unix(self, file, family, inodes, filter_pid=None): f.readline() # skip the first line for line in f: tokens = line.split() - _, _, _, _, type_, _, inode = tokens[0:7] + try: + _, _, _, _, type_, _, inode = tokens[0:7] + except ValueError: + raise RuntimeError( + "error while parsing %s; malformed line %r" % ( + file, line)) if inode in inodes: # With UNIX sockets we can have a single inode # referencing many file descriptors. diff --git a/test/test_psutil.py b/test/test_psutil.py index 66209ead0..50749c46c 100644 --- a/test/test_psutil.py +++ b/test/test_psutil.py @@ -1560,6 +1560,8 @@ def test_prog_w_funky_name(self): subprocess.check_call(["gcc", c_file, "-o", funky_name]) sproc = get_test_subprocess([funky_name, "arg1", "arg2"]) p = psutil.Process(sproc.pid) + # ...in order to try to prevent occasional failures on travis + wait_for_pid(p.pid) self.assertEqual(p.name(), "foo bar )") self.assertEqual(p.exe(), "/tmp/foo bar )") self.assertEqual(p.cmdline(), ["/tmp/foo bar )", "arg1", "arg2"])