diff --git a/platypush/plugins/serial/__init__.py b/platypush/plugins/serial/__init__.py index 8c8cff31cc..99976c0030 100644 --- a/platypush/plugins/serial/__init__.py +++ b/platypush/plugins/serial/__init__.py @@ -131,15 +131,19 @@ class SerialPlugin(GpioSensorPlugin): if isinstance(data, str): data = data.encode('utf-8') - with self.serial_lock: - try: - ser = self._get_serial() - except: - time.sleep(1) - ser = self._get_serial(reset=True) + try: + serial_available = self.serial_lock.acquire(timeout=2) + if serial_available: + try: + ser = self._get_serial() + except: + time.sleep(1) + ser = self._get_serial(reset=True) - self.logger.info('Writing {} to {}'.format(data, self.device)) - ser.write(data) + self.logger.info('Writing {} to {}'.format(data, self.device)) + ser.write(data) + finally: + self.serial_lock.release() # vim:sw=4:ts=4:et: