Skip to content

Commit 9c32628

Browse files
committed
posix: allow calling cancel functions w/o error if port is closed
1 parent ae59fd0 commit 9c32628

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

serial/serialposix.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,10 +518,12 @@ def read(self, size=1):
518518
return bytes(read)
519519

520520
def cancel_read(self):
521-
os.write(self.pipe_abort_read_w, b"x")
521+
if self.is_open:
522+
os.write(self.pipe_abort_read_w, b"x")
522523

523524
def cancel_write(self):
524-
os.write(self.pipe_abort_write_w, b"x")
525+
if self.is_open:
526+
os.write(self.pipe_abort_write_w, b"x")
525527

526528
def write(self, data):
527529
"""Output the given byte string over the serial port."""

0 commit comments

Comments
 (0)