2525class Network (MutableMapping ):
2626 """Representation of one CAN bus containing one or more nodes."""
2727
28+ NOTIFIER_CYCLE : float = 1.0 #: Maximum waiting time for one notifier iteration.
29+ NOTIFIER_SHUTDOWN_TIMEOUT : float = 5.0 #: Maximum waiting time to stop notifiers.
30+
2831 def __init__ (self , bus : Optional [can .BusABC ] = None ):
2932 """
3033 :param can.BusABC bus:
@@ -38,7 +41,7 @@ def __init__(self, bus: Optional[can.BusABC] = None):
3841 #: List of :class:`can.Listener` objects.
3942 #: Includes at least MessageListener.
4043 self .listeners = [MessageListener (self )]
41- self .notifier = None
44+ self .notifier : Optional [ can . Notifier ] = None
4245 self .nodes : Dict [int , Union [RemoteNode , LocalNode ]] = {}
4346 self .subscribers : Dict [int , List [Callback ]] = {}
4447 self .send_lock = threading .Lock ()
@@ -105,7 +108,7 @@ def connect(self, *args, **kwargs) -> Network:
105108 if self .bus is None :
106109 self .bus = can .Bus (* args , ** kwargs )
107110 logger .info ("Connected to '%s'" , self .bus .channel_info )
108- self .notifier = can .Notifier (self .bus , self .listeners , 1 )
111+ self .notifier = can .Notifier (self .bus , self .listeners , self . NOTIFIER_CYCLE )
109112 return self
110113
111114 def disconnect (self ) -> None :
@@ -117,7 +120,7 @@ def disconnect(self) -> None:
117120 if hasattr (node , "pdo" ):
118121 node .pdo .stop ()
119122 if self .notifier is not None :
120- self .notifier .stop ()
123+ self .notifier .stop (self . NOTIFIER_SHUTDOWN_TIMEOUT )
121124 if self .bus is not None :
122125 self .bus .shutdown ()
123126 self .bus = None
@@ -308,7 +311,6 @@ def __init__(
308311 self .msg = can .Message (is_extended_id = can_id > 0x7FF ,
309312 arbitration_id = can_id ,
310313 data = data , is_remote_frame = remote )
311- self ._task = None
312314 self ._start ()
313315
314316 def _start (self ):
0 commit comments