Skip to content

Commit 7486445

Browse files
committed
Minor improvements
1 parent c1e3659 commit 7486445

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

canopen/async_guard.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
""" Utils for async """
22
import functools
3+
import logging
34
import threading
5+
import traceback
46

57
# NOTE: Global, but needed to be able to use ensure_not_async() in
68
# decorator context.
79
_ASYNC_SENTINELS: dict[int, bool] = {}
810

11+
logger = logging.getLogger(__name__)
12+
913

1014
def set_async_sentinel(enable: bool):
1115
""" Register a function to validate if async is running """
@@ -19,6 +23,8 @@ def ensure_not_async(fn):
1923
@functools.wraps(fn)
2024
def async_guard_wrap(*args, **kwargs):
2125
if _ASYNC_SENTINELS.get(threading.get_ident(), False):
22-
raise RuntimeError(f"Calling a blocking function in async. {fn.__qualname__}() in {fn.__code__.co_filename}:{fn.__code__.co_firstlineno}, while running async")
26+
st = "".join(traceback.format_stack())
27+
logger.debug("Traceback:\n%s", st.rstrip())
28+
raise RuntimeError(f"Calling a blocking function, {fn.__qualname__}() in {fn.__code__.co_filename}:{fn.__code__.co_firstlineno}, while running async")
2329
return fn(*args, **kwargs)
2430
return async_guard_wrap

canopen/nmt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def __init__(self, node_id: int):
5656
self.network: canopen.network.Network = canopen.network._UNINITIALIZED_NETWORK
5757
self._state = 0
5858

59-
# @callback - NOTE: called from another thread
59+
# @callback # NOTE: called from another thread
6060
def on_command(self, can_id, data, timestamp):
6161
cmd, node_id = struct.unpack_from("BB", data)
6262
if node_id in (self.id, 0):

0 commit comments

Comments
 (0)