8
8
9
9
import queue # pylint: disable=import-error
10
10
import threading
11
+ import time
11
12
12
13
from instana .log import logger
13
- from instana .util import DictionaryOfStan , every
14
+ from instana .util import DictionaryOfStan
14
15
15
16
16
17
class BaseCollector (object ):
@@ -76,22 +77,22 @@ def start(self):
76
77
"""
77
78
if self .is_reporting_thread_running ():
78
79
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
80
83
timer = threading .Timer (5 , self .start )
81
84
timer .daemon = True
82
85
timer .name = "Collector Timed Start"
83
86
timer .start ()
84
87
return
85
88
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 } )"
88
90
)
89
- return
90
91
91
92
if self .agent .can_send ():
92
93
logger .debug ("BaseCollector.start: launching collection thread" )
93
94
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 = ())
95
96
self .reporting_thread .daemon = True
96
97
self .reporting_thread .name = self .THREAD_NAME
97
98
self .reporting_thread .start ()
@@ -113,37 +114,25 @@ def shutdown(self, report_final=True):
113
114
self .prepare_and_report_data ()
114
115
self .started = False
115
116
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 :
128
118
"""
129
119
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 ()
139
120
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
145
133
146
- return True
134
+ self .prepare_and_report_data ()
135
+ time .sleep (self .report_interval )
147
136
148
137
def prepare_and_report_data (self ):
149
138
"""
0 commit comments