From a3d2ea37d57bb29a2e522c61f35a76abab871d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Mon, 1 Apr 2019 14:36:11 +0200 Subject: [PATCH] Fix exception leaving app in IO block (use non-blocing IO to teardown writer) --- pipe_io_server/pipe_writer_thread.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pipe_io_server/pipe_writer_thread.py b/pipe_io_server/pipe_writer_thread.py index 77d3518..c73a057 100644 --- a/pipe_io_server/pipe_writer_thread.py +++ b/pipe_io_server/pipe_writer_thread.py @@ -1,5 +1,8 @@ -from threading import Thread +from contextlib import suppress +from os import O_NONBLOCK, O_RDONLY, close +from os import open as osopen from queue import Queue +from threading import Thread from .terminate_process_on_failure import terminate_process_on_failure @@ -34,4 +37,6 @@ class PipeWriterThread(Thread): def unblock(self): self._write_queue.put(None) - open(self._pipe_path, 'rb').close() + with suppress(OSError): + fd = osopen(self._pipe_path, O_RDONLY | O_NONBLOCK) + close(fd)