Created
December 19, 2013 21:48
-
-
Save asonge/8046803 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from subprocess import PIPE, Popen | |
from threading import Thread | |
try: | |
from Queue import Queue, Empty | |
except ImportError: | |
from queue import Queue, Empty | |
ON_POSIX = 'posix' in sys.builtin_module_names | |
def enqueue_output(out, queue): | |
for line in iter(out.readline, b''): | |
queue.put(line.rstrip()) | |
out.close() | |
queue.put(None) | |
stdoutq = Queue() | |
print time.time() | |
p = Popen(sys.argv[1:], stdout=PIPE, stderr=PIPE, bufsize=1, close_fds=ON_POSIX) | |
print time.time() | |
t = Thread(target=enqueue_output, args=(p.stdout, stdoutq)) | |
print time.time() | |
t.daemon = True | |
print time.time() | |
t.start() | |
print time.time() | |
standard_out = [] | |
standard_err = [] | |
outline = stdoutq.get() | |
while outline: | |
print outline | |
standard_out.append(outline) | |
outline = stdoutq.get() | |
print time.time() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment