From 0537d1fcac208932d6694f5cd0d5b710fd4a3271 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Wed, 5 Sep 2018 01:59:55 +0200 Subject: [PATCH] serial.write should have a blocking wait if the serial port is busy --- platypush/plugins/serial/__init__.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/platypush/plugins/serial/__init__.py b/platypush/plugins/serial/__init__.py index 99976c003..8c8cff31c 100644 --- a/platypush/plugins/serial/__init__.py +++ b/platypush/plugins/serial/__init__.py @@ -131,19 +131,15 @@ class SerialPlugin(GpioSensorPlugin): if isinstance(data, str): data = data.encode('utf-8') - 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) + with self.serial_lock: + 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) - finally: - self.serial_lock.release() + self.logger.info('Writing {} to {}'.format(data, self.device)) + ser.write(data) # vim:sw=4:ts=4:et: