Skip to content

Commit

Permalink
fix isotp timeoutscheduler logging
Browse files Browse the repository at this point in the history
  • Loading branch information
polybassa committed May 1, 2023
1 parent e37ee78 commit 31321ba
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions scapy/contrib/isotp/isotp_soft_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
Callable,
TYPE_CHECKING,
)

if TYPE_CHECKING:
from scapy.contrib.cansocket import CANSocket

Expand Down Expand Up @@ -223,6 +224,8 @@ class TimeoutScheduler:
# use heapq functions on _handles!
_handles = [] # type: List[TimeoutScheduler.Handle]

logger = logging.getLogger("scapy.contrib.automotive.timeout_scheduler")

@classmethod
def schedule(cls, timeout, callback):
# type: (float, Callable[[], None]) -> TimeoutScheduler.Handle
Expand Down Expand Up @@ -311,13 +314,13 @@ def _wait(cls, handle):
# Wait until the next timeout,
# or until event.set() gets called in another thread.
if to_wait > 0:
log_isotp.debug("TimeoutScheduler Thread going to sleep @ %f " +
"for %fs", now, to_wait)
cls.logger.debug("Thread going to sleep @ %f " +
"for %fs", now, to_wait)
interrupted = cls._event.wait(to_wait)
new = cls._time()
log_isotp.debug("TimeoutScheduler Thread awake @ %f, slept for" +
" %f, interrupted=%d", new, new - now,
interrupted)
cls.logger.debug("Thread awake @ %f, slept for" +
" %f, interrupted=%d", new, new - now,
interrupted)

# Clear the event so that we can wait on it again,
# Must be done before doing the callbacks to avoid losing a set().
Expand All @@ -330,7 +333,7 @@ def _task(cls):
start when the first timeout is added and stop when the last timeout
is removed or executed."""

log_isotp.debug("TimeoutScheduler Thread spawning @ %f", cls._time())
cls.logger.debug("Thread spawning @ %f", cls._time())

time_empty = None

Expand All @@ -352,7 +355,7 @@ def _task(cls):
finally:
# Worst case scenario: if this thread dies, the next scheduled
# timeout will start a new one
log_isotp.debug("TimeoutScheduler Thread died @ %f", cls._time())
cls.logger.debug("Thread died @ %f", cls._time())
cls._thread = None

@classmethod
Expand Down
5 changes: 3 additions & 2 deletions scapy/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import types
import warnings

from typing_extensions import Self

from scapy.fields import (
AnyField,
BitField,
Expand Down Expand Up @@ -61,9 +63,8 @@
TypeVar,
Union,
Sequence,
cast,
cast
)
from scapy.compat import Self

try:
import pyx
Expand Down

0 comments on commit 31321ba

Please sign in to comment.