Skip to content

Commit 80ca49f

Browse files
authored
Merge pull request hardbyte#397 from hardbyte/fix-issue-394
Fix issue hardbyte#394
2 parents 7acf9fd + 0ecc555 commit 80ca49f

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

can/thread_safe_bus.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818

1919

2020
try:
21-
from contextlib import nullcontext as NullContextManager
21+
from contextlib import nullcontext
2222

2323
except ImportError:
24-
class NullContextManager(object):
24+
class nullcontext(object):
2525
"""A context manager that does nothing at all.
2626
A fallback for Python 3.7's :class:`contextlib.nullcontext` manager.
2727
"""
@@ -53,10 +53,6 @@ class ThreadSafeBus(ObjectProxy):
5353
instead of :meth:`~can.BusABC.recv` directly.
5454
"""
5555

56-
# init locks for sending and receiving separately
57-
_lock_send = RLock()
58-
_lock_recv = RLock()
59-
6056
def __init__(self, *args, **kwargs):
6157
if import_exc is not None:
6258
raise import_exc
@@ -65,7 +61,11 @@ def __init__(self, *args, **kwargs):
6561

6662
# now, BusABC.send_periodic() does not need a lock anymore, but the
6763
# implementation still requires a context manager
68-
self.__wrapped__._lock_send_periodic = NullContextManager()
64+
self.__wrapped__._lock_send_periodic = nullcontext()
65+
66+
# init locks for sending and receiving separately
67+
self._lock_send = RLock()
68+
self._lock_recv = RLock()
6969

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

0 commit comments

Comments
 (0)