summaryrefslogtreecommitdiff
path: root/serial/serialposix.py
diff options
context:
space:
mode:
Diffstat (limited to 'serial/serialposix.py')
-rw-r--r--serial/serialposix.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/serial/serialposix.py b/serial/serialposix.py
index 01848e9..e6ef534 100644
--- a/serial/serialposix.py
+++ b/serial/serialposix.py
@@ -302,6 +302,17 @@ class Serial(SerialBase, PlatformSpecific):
"""Set communication parameters on opened port."""
if self.fd is None:
raise SerialException("Can only operate on a valid file descriptor")
+
+ # if exclusive lock is requested, create it before we modify anything else
+ if self._exclusive is not None:
+ if self._exclusive:
+ try:
+ fcntl.flock(self.fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
+ except IOError as msg:
+ raise SerialException(msg.errno, "Could not exclusively lock port {}: {}".format(self._port, msg))
+ else:
+ fcntl.flock(self.fd, fcntl.LOCK_UN)
+
custom_baud = None
vmin = vtime = 0 # timeout is done via select