From 282cf75a77c7511f780f3c253a09d61e370ff5d5 Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Sat, 20 Mar 2021 01:56:29 +0100 Subject: [PATCH] Close pipe's write fd before the read one This should theoretically get rid of one possible exception ("Broken pipe") happening in `Bus._transition()` due to a race condition. Ref #16 --- magicbus/base.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/magicbus/base.py b/magicbus/base.py index fdda16b8..2a2a68f8 100644 --- a/magicbus/base.py +++ b/magicbus/base.py @@ -352,8 +352,10 @@ def _wait(): self.publish(channel) finally: self._state_transition_pipes.discard(pipe) - os.close(read_fd) + # NOTE: Closing the write file descriptor first + # NOTE: to prevent "Broken pipe" in `self._transition()`. os.close(write_fd) + os.close(read_fd) # From http://psyco.sourceforge.net/psycoguide/bugs.html: # "The compiled machine code does not include the regular polling