From 4e67cab743f1f0ab638d81d4cf71e198811ebd20 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 24 Aug 2018 10:27:06 +0200 Subject: [PATCH 1/2] fix #394 --- can/thread_safe_bus.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/can/thread_safe_bus.py b/can/thread_safe_bus.py index ac1a85a83..a61774231 100644 --- a/can/thread_safe_bus.py +++ b/can/thread_safe_bus.py @@ -18,10 +18,10 @@ try: - from contextlib import nullcontext as NullContextManager + from contextlib import nullcontext except ImportError: - class NullContextManager(object): + class nullcontext(object): """A context manager that does nothing at all. A fallback for Python 3.7's :class:`contextlib.nullcontext` manager. """ @@ -53,10 +53,6 @@ class ThreadSafeBus(ObjectProxy): instead of :meth:`~can.BusABC.recv` directly. """ - # init locks for sending and receiving separately - _lock_send = RLock() - _lock_recv = RLock() - def __init__(self, *args, **kwargs): if import_exc is not None: raise import_exc @@ -65,7 +61,11 @@ def __init__(self, *args, **kwargs): # now, BusABC.send_periodic() does not need a lock anymore, but the # implementation still requires a context manager - self.__wrapped__._lock_send_periodic = NullContextManager() + self.__wrapped__._lock_send_periodic = nullcontext() + + # init locks for sending and receiving separately + _lock_send = RLock() + _lock_recv = RLock() def recv(self, timeout=None, *args, **kwargs): with self._lock_recv: From 0ecc555e2fbae0ac552c1f1f0135626a55179627 Mon Sep 17 00:00:00 2001 From: Felix Divo Date: Fri, 24 Aug 2018 22:24:22 +0200 Subject: [PATCH 2/2] fix stupid bug --- can/thread_safe_bus.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/can/thread_safe_bus.py b/can/thread_safe_bus.py index a61774231..1b0f75a2d 100644 --- a/can/thread_safe_bus.py +++ b/can/thread_safe_bus.py @@ -64,8 +64,8 @@ def __init__(self, *args, **kwargs): self.__wrapped__._lock_send_periodic = nullcontext() # init locks for sending and receiving separately - _lock_send = RLock() - _lock_recv = RLock() + self._lock_send = RLock() + self._lock_recv = RLock() def recv(self, timeout=None, *args, **kwargs): with self._lock_recv: