Skip to content
Merged
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion can/bus.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def send_periodic(
Disable to instead manage tasks manually.
:return:
A started task instance. Note the task can be stopped (and depending on
the backend modified) by calling the :meth:`stop` method.
the backend modified) by calling the task's :meth:`stop` method.

.. note::

Expand Down Expand Up @@ -430,3 +430,6 @@ def _detect_available_configs() -> List[can.typechecking.AutoDetectedConfig]:
for usage in the interface's bus constructor.
"""
raise NotImplementedError()

def fileno(self) -> int:
raise NotImplementedError("fileno is not implemented using current CAN bus")
25 changes: 14 additions & 11 deletions can/notifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,26 @@ def add_bus(self, bus: BusABC):
:param bus:
CAN bus instance.
"""
if (
self._loop is not None
and hasattr(bus, "fileno")
and bus.fileno() >= 0 # type: ignore
):
# Use file descriptor to watch for messages
reader = bus.fileno() # type: ignore
reader: int = -1
try:
reader = bus.fileno()
except NotImplementedError:
# Bus doesn't support fileno, we fall back to thread based reader
pass

if self._loop is not None and reader >= 0:
# Use bus file descriptor to watch for messages
self._loop.add_reader(reader, self._on_message_available, bus)
self._readers.append(reader)
else:
reader = threading.Thread(
reader_thread = threading.Thread(
target=self._rx_thread,
args=(bus,),
name='can.notifier for bus "{}"'.format(bus.channel_info),
)
reader.daemon = True
reader.start()
self._readers.append(reader)
reader_thread.daemon = True
reader_thread.start()
self._readers.append(reader_thread)

def stop(self, timeout: float = 5):
"""Stop notifying Listeners when new :class:`~can.Message` objects arrive
Expand Down