diff options
author | Rob Gaddi <rgaddi@highlandtechnology.com> | 2017-02-24 11:39:46 -0800 |
---|---|---|
committer | Rob Gaddi <rgaddi@highlandtechnology.com> | 2017-02-24 11:39:46 -0800 |
commit | 636cc64cc949076fe9051cc4b971384006eafee2 (patch) | |
tree | 51b5fa53b3a92ef6d8f6a851c29f0cb3b7ab1e23 /serial/serialposix.py | |
parent | ffb44d6d7394e2b73bfb1bb91dd69c377c0f8aa0 (diff) | |
download | pyserial-git-636cc64cc949076fe9051cc4b971384006eafee2.tar.gz |
Added exclusive locking for POSIX serial ports.
Diffstat (limited to 'serial/serialposix.py')
-rw-r--r-- | serial/serialposix.py | 11 |
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 |