diff options
author | Chris Liechti <cliechti@gmx.net> | 2017-07-15 01:58:56 +0200 |
---|---|---|
committer | Chris Liechti <cliechti@gmx.net> | 2017-07-15 01:58:56 +0200 |
commit | 9c32628331735c8016b00c829089c1e2812e03d9 (patch) | |
tree | 48c58af7770b06dd919d282a3485c0e44fb8600d | |
parent | ae59fd0f5a02d8b69c3c114e40775c3e1b1c6470 (diff) | |
download | pyserial-git-9c32628331735c8016b00c829089c1e2812e03d9.tar.gz |
posix: allow calling cancel functions w/o error if port is closed
-rw-r--r-- | serial/serialposix.py | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py index 195ecd4..afe5062 100644 --- a/serial/serialposix.py +++ b/serial/serialposix.py @@ -518,10 +518,12 @@ class Serial(SerialBase, PlatformSpecific): return bytes(read) def cancel_read(self): - os.write(self.pipe_abort_read_w, b"x") + if self.is_open: + os.write(self.pipe_abort_read_w, b"x") def cancel_write(self): - os.write(self.pipe_abort_write_w, b"x") + if self.is_open: + os.write(self.pipe_abort_write_w, b"x") def write(self, data): """Output the given byte string over the serial port.""" |