##// END OF EJS Templates
Don't use select() in StreamCapturer...
Thomas Kluyver -
Show More
@@ -31,7 +31,6 b' import glob'
31 31 from io import BytesIO
32 32 import os
33 33 import os.path as path
34 from select import select
35 34 import sys
36 35 from threading import Thread, Lock, Event
37 36 import warnings
@@ -373,11 +372,10 b' class StreamCapturer(Thread):'
373 372 self.started = True
374 373
375 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:
379 377 with self.buffer_lock:
380 self.buffer.write(os.read(self.readfd, 1024))
378 self.buffer.write(chunk)
381 379
382 380 os.close(self.readfd)
383 381 os.close(self.writefd)
@@ -395,6 +393,15 b' class StreamCapturer(Thread):'
395 393 if not self.started:
396 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 405 class SubprocessStreamCapturePlugin(Plugin):
399 406 name='subprocstreams'
400 407 def __init__(self):
@@ -429,9 +436,7 b' class SubprocessStreamCapturePlugin(Plugin):'
429 436 formatError = formatFailure
430 437
431 438 def finalize(self, result):
432 if self.stream_capturer.started:
433 self.stream_capturer.stop.set()
434 self.stream_capturer.join()
439 self.stream_capturer.halt()
435 440
436 441
437 442 def run_iptest():
General Comments 0
You need to be logged in to leave comments. Login now