##// END OF EJS Templates
Don't use select() in StreamCapturer...
Thomas Kluyver -
Show More
@@ -31,7 +31,6 b' import glob'
31 from io import BytesIO
31 from io import BytesIO
32 import os
32 import os
33 import os.path as path
33 import os.path as path
34 from select import select
35 import sys
34 import sys
36 from threading import Thread, Lock, Event
35 from threading import Thread, Lock, Event
37 import warnings
36 import warnings
@@ -373,28 +372,36 b' class StreamCapturer(Thread):'
373 self.started = True
372 self.started = True
374
373
375 while not self.stop.is_set():
374 while not self.stop.is_set():
376 ready = select([self.readfd], [], [], 1)[0]
375 chunk = os.read(self.readfd, 1024)
377
376
378 if ready:
377 with self.buffer_lock:
379 with self.buffer_lock:
378 self.buffer.write(chunk)
380 self.buffer.write(os.read(self.readfd, 1024))
381
379
382 os.close(self.readfd)
380 os.close(self.readfd)
383 os.close(self.writefd)
381 os.close(self.writefd)
384
382
385 def reset_buffer(self):
383 def reset_buffer(self):
386 with self.buffer_lock:
384 with self.buffer_lock:
387 self.buffer.truncate(0)
385 self.buffer.truncate(0)
388 self.buffer.seek(0)
386 self.buffer.seek(0)
389
387
390 def get_buffer(self):
388 def get_buffer(self):
391 with self.buffer_lock:
389 with self.buffer_lock:
392 return self.buffer.getvalue()
390 return self.buffer.getvalue()
393
391
394 def ensure_started(self):
392 def ensure_started(self):
395 if not self.started:
393 if not self.started:
396 self.start()
394 self.start()
397
395
396 def halt(self):
397 """Safely stop the thread."""
398 if not self.started:
399 return
400
401 self.stop.set()
402 os.write(self.writefd, b'wake up') # Ensure we're not locked in a read()
403 self.join()
404
398 class SubprocessStreamCapturePlugin(Plugin):
405 class SubprocessStreamCapturePlugin(Plugin):
399 name='subprocstreams'
406 name='subprocstreams'
400 def __init__(self):
407 def __init__(self):
@@ -429,9 +436,7 b' class SubprocessStreamCapturePlugin(Plugin):'
429 formatError = formatFailure
436 formatError = formatFailure
430
437
431 def finalize(self, result):
438 def finalize(self, result):
432 if self.stream_capturer.started:
439 self.stream_capturer.halt()
433 self.stream_capturer.stop.set()
434 self.stream_capturer.join()
435
440
436
441
437 def run_iptest():
442 def run_iptest():
General Comments 0
You need to be logged in to leave comments. Login now