[issue5673] Add timeout option to subprocess.Popen

Reid Kleckner report at bugs.python.org
Fri Jul 16 17:39:03 CEST 2010


Reid Kleckner <rnk at mit.edu> added the comment:

I forgot that I had to tweak the test as well as subprocess.py.  I did a .replace('\r', ''), but universal newlines is better.

Looking at the open questions I had about the Windows threads, I think it'll be OK if the user follows the pattern of:
proc = subprocess.Popen(...)
try:
    stdout, stderr = proc.communicate(timeout=...)
except subprocess.TimeoutExpired:
    proc.kill()
    stdout, stderr = proc.communicate()

If the child process is deadlocked and the user doesn't kill it, then the file descriptors will be leaked and the daemon threads will also live on forever.  I *think* that's the worst that could happen.  Or they could of course wakeup during interpreter shutdown and cause tracebacks, but that's highly unlikely, and already possible currently.

Anyway, I would say we can't avoid leaking the fds in that situation, because we can't know if the user will eventually ask us for the data or not.  If they want to avoid the leak, they can clean up after themselves.

What's the next step for getting this in?  Thanks to those who've taken time to look at this so far.

----------
Added file: http://bugs.python.org/file18028/subprocess-timeout-v5.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5673>
_______________________________________


More information about the Python-bugs-list mailing list