Fix unblock race condition randomly leading to deadlocks
This commit is contained in:
parent
ca613644ac
commit
dbe5b10482
@ -34,11 +34,13 @@ class PipeReaderThread(Thread):
|
|||||||
return open(self._pipe_path, 'rb')
|
return open(self._pipe_path, 'rb')
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.unblock()
|
self._unblock()
|
||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
def unblock(self):
|
def _unblock(self):
|
||||||
with suppress(OSError):
|
while True:
|
||||||
fd = osopen(self._pipe_path, O_WRONLY | O_NONBLOCK)
|
with suppress(OSError):
|
||||||
write(fd, self.stop_sequence)
|
fd = osopen(self._pipe_path, O_WRONLY | O_NONBLOCK)
|
||||||
close(fd)
|
write(fd, self.stop_sequence)
|
||||||
|
close(fd)
|
||||||
|
break
|
||||||
|
@ -39,11 +39,13 @@ class PipeWriterThread(Thread):
|
|||||||
return open(self._pipe_path, 'wb')
|
return open(self._pipe_path, 'wb')
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.unblock()
|
self._unblock()
|
||||||
self.join()
|
self.join()
|
||||||
|
|
||||||
def unblock(self):
|
def _unblock(self):
|
||||||
self._write_queue.push_front(None)
|
while True:
|
||||||
with suppress(OSError):
|
with suppress(OSError):
|
||||||
fd = osopen(self._pipe_path, O_RDONLY | O_NONBLOCK)
|
fd = osopen(self._pipe_path, O_RDONLY | O_NONBLOCK)
|
||||||
close(fd)
|
self._write_queue.push_front(None)
|
||||||
|
close(fd)
|
||||||
|
break
|
||||||
|
Loading…
Reference in New Issue
Block a user