Skip to content

Commit 093509a

Browse files
authored
Improved listener docs and docstrings (#484)
1 parent 9453cd0 commit 093509a

File tree

7 files changed

+26
-10
lines changed

7 files changed

+26
-10
lines changed

can/io/csv.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from can.listener import Listener
2020
from .generic import BaseIOHandler
2121

22+
2223
class CSVWriter(BaseIOHandler, Listener):
2324
"""Writes a comma separated text file with a line for
2425
each message. Includes a header line.
@@ -37,13 +38,13 @@ class CSVWriter(BaseIOHandler, Listener):
3738
data base64 encoded WzQyLCA5XQ==
3839
================ ======================= ===============
3940
40-
Each line is terminated with a platform specific line seperator.
41+
Each line is terminated with a platform specific line separator.
4142
"""
4243

4344
def __init__(self, file, append=False):
4445
"""
45-
:param file: a path-like object or as file-like object to write to
46-
If this is a file-like object, is has to opened in text
46+
:param file: a path-like object or a file-like object to write to.
47+
If this is a file-like object, is has to open in text
4748
write mode, not binary write mode.
4849
:param bool append: if set to `True` messages are appended to
4950
the file and no header line is written, else

can/io/logger.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ class Logger(BaseIOHandler, Listener):
3232
* .log :class:`can.CanutilsLogWriter`
3333
* other: :class:`can.Printer`
3434
35+
The log files may be incomplete until `stop()` is called due to buffering.
36+
3537
.. note::
3638
This class itself is just a dispatcher, and any positional an keyword
3739
arguments are passed on to the returned instance.

can/io/sqlite.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def _db_writer_thread(self):
228228

229229
def stop(self):
230230
"""Stops the reader an writes all remaining messages to the database. Thus, this
231-
might take a while an block.
231+
might take a while and block.
232232
"""
233233
BufferedReader.stop(self)
234234
self._stop_running_event.set()

can/listener.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class Listener(object):
3535
# or
3636
listener.on_message_received(msg)
3737
38+
# Important to ensure all outputs are flushed
39+
listener.stop()
3840
"""
3941

4042
__metaclass__ = ABCMeta
@@ -59,7 +61,10 @@ def on_error(self, exc):
5961

6062
def stop(self):
6163
"""
62-
Override to cleanup any open resources.
64+
Stop handling new messages, carry out any final tasks to ensure
65+
data is persisted and cleanup any open resources.
66+
67+
Concrete implementations override.
6368
"""
6469

6570

can/notifier.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@
1818
class Notifier(object):
1919

2020
def __init__(self, bus, listeners, timeout=1.0, loop=None):
21-
"""Manages the distribution of **Messages** from a given bus/buses to a
22-
list of listeners.
21+
"""Manages the distribution of :class:`can.Message` instances to listeners.
22+
23+
Supports multiple busses and listeners.
24+
25+
.. Note::
26+
27+
Remember to call `stop()` after all messages are received as
28+
many listeners carry out flush operations to persist data.
29+
2330
2431
:param can.BusABC bus: A :ref:`bus` or a list of buses to listen to.
2532
:param list listeners: An iterable of :class:`~can.Listener`

doc/asyncio.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ Asyncio support
44
===============
55

66
The :mod:`asyncio` module built into Python 3.4 and later can be used to write
7-
asynchronos code in a single thread. This library supports receiving messages
8-
asynchronosly in an event loop using the :class:`can.Notifier` class.
7+
asynchronous code in a single thread. This library supports receiving messages
8+
asynchronously in an event loop using the :class:`can.Notifier` class.
9+
910
There will still be one thread per CAN bus but the user application will execute
1011
entirely in the event loop, allowing simpler concurrency without worrying about
1112
threading issues. Interfaces that have a valid file descriptor will however be

doc/listeners.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ and are listed below.
2424
Some of them allow messages to be written to files, and the corresponding file
2525
readers are also documented here.
2626

27-
.. warning ::
27+
.. note ::
2828
2929
Please note that writing and the reading a message might not always yield a
3030
completely unchanged message again, since some properties are not (yet)

0 commit comments

Comments
 (0)