Open ZachGoldberg opened 12 years ago
Correction, other netinfo calls also leak sockets. get_broadcast() being the largest offender I've identified thus far.
I wrote the following decorator for use around functions that call netinfo (and preferably only netinfo) to cleanup the leaked FDs.
def ensure_no_leaked_fds(function):
def wrapper(*args, **kwargs):
original_fds = [int(i) for i in os.listdir(
"/proc/%s/fd/" % os.getpid()) if int(i) > 10]
retval = function(*args, **kwargs)
post_fds = [int(i) for i in os.listdir(
"/proc/%s/fd/" % os.getpid()) if int(i) > 10]
new_fds = set(post_fds) - set(original_fds)
for fd in new_fds:
try:
f = os.fdopen(fd)
f.close()
except:
pass
return retval
return wrapper
Hi Zach,
Thanks for your report, sorry it has taken so long for me to attend to it. I will hopefully have some time to deal with the issue over the next couple of days.
Thanks Sassan
Everytime I call netinfo.list_active_devs() approximately 15 sockets are leaked. I call list_active_devs once every couple of seconds and therefore this causes my application to crash after a few minutes.
Exception: (24, 'Too many open files') Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/apport_python_hook.py", line 59, in apport_excepthook ImportError: No module named fileutils