@@ -605,25 +605,29 @@ def enable(self) -> None:
605605 self .enabled = False
606606 raise err
607607 if not result :
608+ _logger .warning ("Failed to enable but no error was raised" )
608609 self .enabled = False
609610 else :
610611 self .enabled = True
611- # Set up data fetching
612612 if self ._using_callback :
613+ _logger .debug ("Setup with callback, disabling fetch thread" )
613614 if self ._fetch_thread :
614615 self ._fetch_thread_run = False
615616 else :
617+ _logger .debug ("Setting up fetch thread" )
616618 if not self ._fetch_thread or not self ._fetch_thread .is_alive ():
617619 self ._fetch_thread = Thread (target = self ._fetch_loop )
618620 self ._fetch_thread .daemon = True
619621 self ._fetch_thread .start ()
620- if (
621- not self ._dispatch_thread
622- or not self ._dispatch_thread .is_alive ()
623- ):
622+
623+ if self ._dispatch_thread and self ._dispatch_thread .is_alive ():
624+ _logger .debug ("Found live dispatch thread." )
625+ else :
626+ _logger .debug ("Setting up dispatch thread" )
624627 self ._dispatch_thread = Thread (target = self ._dispatch_loop )
625628 self ._dispatch_thread .daemon = True
626629 self ._dispatch_thread .start ()
630+
627631 _logger .debug ("... enabled." )
628632
629633 def disable (self ) -> None :
@@ -635,8 +639,10 @@ def disable(self) -> None:
635639 self .enabled = False
636640 if self ._fetch_thread :
637641 if self ._fetch_thread .is_alive ():
642+ _logger .debug ("Found fetch thread alive. Joining." )
638643 self ._fetch_thread_run = False
639644 self ._fetch_thread .join ()
645+ _logger .debug ("Fetch thread is dead." )
640646 super ().disable ()
641647
642648 @abc .abstractmethod
@@ -651,14 +657,15 @@ def _fetch_data(self) -> None:
651657 data is available, return `None`.
652658
653659 """
654- return None
660+ raise NotImplementedError ()
655661
656662 def _process_data (self , data ):
657663 """Do any data processing and return data."""
658664 return data
659665
660666 def _send_data (self , client , data , timestamp ):
661667 """Dispatch data to the client."""
668+ _logger .debug ("sending data to client" )
662669 try :
663670 # Cockpit will send a client with receiveData and expects
664671 # two arguments (data and timestamp). But we really want
@@ -684,8 +691,10 @@ def _send_data(self, client, data, timestamp):
684691 def _dispatch_loop (self ) -> None :
685692 """Process data and send results to any client."""
686693 while True :
694+ _logger .debug ("Getting data from dispatch buffer" )
687695 client , data , timestamp = self ._dispatch_buffer .get (block = True )
688696 if client not in self ._liveClients :
697+ _logger .debug ("Client not in liveClients so ignoring data." )
689698 continue
690699 err = None
691700 if isinstance (data , Exception ):
@@ -712,6 +721,7 @@ def _fetch_loop(self) -> None:
712721 self ._fetch_thread_run = True
713722
714723 while self ._fetch_thread_run :
724+ _logger .debug ("Fetching data from device." )
715725 try :
716726 data = self ._fetch_data ()
717727 except Exception as e :
@@ -722,10 +732,12 @@ def _fetch_loop(self) -> None:
722732 self ._put (e , timestamp )
723733 data = None
724734 if data is not None :
735+ _logger .debug ("Fetch data to be put into dispatch buffer." )
725736 # TODO Add support for timestamp from hardware.
726737 timestamp = time .time ()
727738 self ._put (data , timestamp )
728739 else :
740+ _logger .debug ("Fetched no data from device." )
729741 time .sleep (0.001 )
730742
731743 @property
0 commit comments