def __init__(self, *, process: subprocess.Popen, encoding: str, tmp_input: FilesystemIPC) -> None:
self.process = process
self.stdout_encoding = encoding
self.iterating = False
#
# We need to capture stderr in a background thread to avoid deadlocks.
# (The problem would occur when dlvhex2 is blocked because the OS buffers on the stderr pipe are full... so we have to constantly read from *both* stdout and stderr)
self.stderr_capture_thread = StreamCaptureThread(self.process.stderr)
self.stderr_capture_thread.start()
#
# Set up finalization. Using weakref.finalize seems to work more robustly than using __del__.
# (One problem that occurred with __del__: It seemed like python was calling __del__ for self.process and its IO streams first,
# which resulted in ResourceWarnings even though we were closing the streams properly in our __del__ function.)
self._finalize = weakref.finalize(self, DlvhexLineReader.__close, process, self.stderr_capture_thread, encoding, tmp_input) # type: ignore
# Make sure the subprocess will be terminated if it's still running when the python process exits
self._finalize.atexit = True
评论列表
文章目录