Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions can/thread_safe_bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand Down Expand Up @@ -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
Expand All @@ -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
self._lock_send = RLock()
self._lock_recv = RLock()

def recv(self, timeout=None, *args, **kwargs):
with self._lock_recv:
Expand Down