I have a small issue that I\'m not quite sure how to solve. Here is a minimal example:
scan_process = subprocess.Popen(command, stdout=su
While Tom's solution works, using select() in the C idiom is more compact, this is the equivalent of your answer:
from select import select
scan_process = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
bufsize=1) # Line buffered
while some_criterium and not time_limit:
poll_result = select([scan_process.stdout], [], [], time_limit)[0]
The rest is the same.
See pydoc select.select.
[Note: this is Unix-specific, as are some of the other answers.]
[Note 2: edited to add line buffering as per OP request]
[Note 3: the line buffering may not be reliable in all circumstances, leading to readline() blocking]