88
99import queue # pylint: disable=import-error
1010import threading
11+ import time
1112
1213from instana .log import logger
13- from instana .util import DictionaryOfStan , every
14+ from instana .util import DictionaryOfStan
1415
1516
1617class BaseCollector (object ):
@@ -76,22 +77,22 @@ def start(self):
7677 """
7778 if self .is_reporting_thread_running ():
7879 if self .thread_shutdown .is_set ():
79- # Shutdown still in progress; Reschedule this start in 5 seconds from now
80+ # Force a restart.
81+ self .thread_shutdown .clear ()
82+ # Reschedule this start in 5 seconds from now
8083 timer = threading .Timer (5 , self .start )
8184 timer .daemon = True
8285 timer .name = "Collector Timed Start"
8386 timer .start ()
8487 return
8588 logger .debug (
86- "BaseCollector.start non-fatal: call but thread already running (started: %s)" ,
87- self .started ,
89+ f"BaseCollector.start non-fatal: call but thread already running (started: { self .started } )"
8890 )
89- return
9091
9192 if self .agent .can_send ():
9293 logger .debug ("BaseCollector.start: launching collection thread" )
9394 self .thread_shutdown .clear ()
94- self .reporting_thread = threading .Thread (target = self .thread_loop , args = ())
95+ self .reporting_thread = threading .Thread (target = self .background_report , args = ())
9596 self .reporting_thread .daemon = True
9697 self .reporting_thread .name = self .THREAD_NAME
9798 self .reporting_thread .start ()
@@ -113,37 +114,25 @@ def shutdown(self, report_final=True):
113114 self .prepare_and_report_data ()
114115 self .started = False
115116
116- def thread_loop (self ):
117- """
118- Just a loop that is run in the background thread.
119- @return: None
120- """
121- every (
122- self .report_interval ,
123- self .background_report ,
124- "Instana Collector: prepare_and_report_data" ,
125- )
126-
127- def background_report (self ):
117+ def background_report (self ) -> None :
128118 """
129119 The main work-horse method to report data in the background thread.
130- @return: Boolean
131- """
132- if self .thread_shutdown .is_set ():
133- logger .debug (
134- "Thread shutdown signal is active: Shutting down reporting thread"
135- )
136- return False
137-
138- self .prepare_and_report_data ()
139120
140- if self .thread_shutdown .is_set ():
141- logger .debug (
142- "Thread shutdown signal is active: Shutting down reporting thread"
143- )
144- return False
121+ This method runs indefinitely, preparing and reporting data at regular
122+ intervals.
123+ It checks for a shutdown signal and stops execution if it's set.
124+
125+ @return: None
126+ """
127+ while True :
128+ if self .thread_shutdown .is_set ():
129+ logger .debug (
130+ "Thread shutdown signal is active: Shutting down reporting thread"
131+ )
132+ break
145133
146- return True
134+ self .prepare_and_report_data ()
135+ time .sleep (self .report_interval )
147136
148137 def prepare_and_report_data (self ):
149138 """
0 commit comments