File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,21 +122,24 @@ def __init__(self):
122122 super ().__init__ ()
123123 # Create a thread-safe queue for log messages
124124 self .log_messages = queue .Queue ()
125+ # Initialize running attribute before starting the thread
126+ self .running = True
125127 # Start a worker thread to process log messages
126128 self .worker_thread = threading .Thread (target = self ._worker , daemon = True )
127129 self .worker_thread .start ()
128- self .running = True
129130
130131 def emit (self , record ):
131- if not self .running :
132+ # Use getattr with default to avoid AttributeError
133+ if not getattr (self , 'running' , True ):
132134 return
133135 log_entry = self .format (record )
134136 # Add to the thread-safe queue
135137 self .log_messages .put (log_entry )
136138
137139 def _worker (self ):
138140 """Worker thread that transfers messages from the thread-safe queue to the asyncio queue."""
139- while self .running :
141+ # Use getattr with default to avoid AttributeError
142+ while getattr (self , 'running' , True ):
140143 try :
141144 # Get message from the thread-safe queue (blocking with timeout)
142145 log_entry = self .log_messages .get (timeout = 0.5 )
@@ -175,8 +178,9 @@ def _worker(self):
175178 continue
176179
177180 def close (self ):
181+ # Set running to False
178182 self .running = False
179- if self .worker_thread .is_alive ():
183+ if hasattr ( self , 'worker_thread' ) and self .worker_thread .is_alive ():
180184 self .worker_thread .join (timeout = 1.0 )
181185 super ().close ()
182186
You can’t perform that action at this time.
0 commit comments