Message141295
There seems to be a file descriptor (fd) leak in subprocess upon call to kill() and then destroying the current subprocess object (e.g. by scope exit) if the pipe functionality is being used.
This is a reproducer:
(Linux 2.6.25, Python 2.7.1 (r271:86832))
import subprocess, time
def leaktest():
subp = subprocess.Popen("echo hi; sleep 200; echo bye", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
#you can do something here
subp.terminate()
#subp.wait() #Fixes the bug
#time.sleep(0.001) #fixes the bug
#time.sleep(0.0000001) #doesn't fix the bug
return True
Launch the function multiple times interactively, each time the number of open file descriptors for the python process will increase by 2. You can see that by "ls -l /proc/<pid>/fd"
This seems to be a race condition because adding a time.sleep(0.001) before the return fixes the problem. Probably some kernel delay is responsible for the race.
This bug is significant for daemons because the daemon will die once the number of open file descriptors hits the ulimit, usually 1024, so please fix.
Note: until the bug is fixed, a simple workaround (not documented in module docs though) is to call Popen.wait() after Popen.kill()
Thank you |
|
Date |
User |
Action |
Args |
2011-07-28 13:59:00 | gabriele.trombetti | set | recipients:
+ gabriele.trombetti |
2011-07-28 13:59:00 | gabriele.trombetti | set | messageid: <1311861540.35.0.103521770573.issue12650@psf.upfronthosting.co.za> |
2011-07-28 13:58:59 | gabriele.trombetti | link | issue12650 messages |
2011-07-28 13:58:59 | gabriele.trombetti | create | |
|