shanecode / psutil

Automatically exported from code.google.com/p/psutil
Other
0 stars 0 forks source link

BSD - get_open_files() doesn't work properly #373

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
...because it returns an empty string:

======================================================================
FAIL: test_get_open_files (__main__.TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_psutil.py", line 1202, in test_get_open_files
    self.assertIn(TESTFN, filenames)
AssertionError: '/home/psutil/psutil/$testfile' not found in 
['/usr/local/bin/python', '']

======================================================================
FAIL: test_get_open_files2 (__main__.TestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "test/test_psutil.py", line 1230, in test_get_open_files2
    self.assertEqual(path, fileobj.name)
AssertionError: '' != '/home/psutil/psutil/$testfile'

This is not new (started since we got rid of the lsof parser implementation I 
guess) but I always ignored it for lack of time and laziness.
At least now we have it tracked.

Original issue reported on code.google.com by g.rodola on 30 Apr 2013 at 7:31

GoogleCodeExporter commented 9 years ago

Original comment by g.rodola on 30 Apr 2013 at 7:33

GoogleCodeExporter commented 9 years ago
Update: it seems this is due to deleted files.

import os
import time

p = psutil.Process(os.getpid())
f = open('xxx', 'w')
time.sleep(.1)
os.remove(f.name)
print p.get_open_files()

...will print:

[openfile(path='/usr/local/bin/python', fd=-5), openfile(path='', fd=3)]

Original comment by g.rodola on 15 May 2013 at 2:21