-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Investigate performance and error handling for send_data_loop:
Lines 295 to 327 in d5a9bbc
| async def _send_data_loop(self): | |
| """Send data to the server every 333ms, batching all available items.""" | |
| try: | |
| while not self.stop_event.is_set() and not self.error_event.is_set(): | |
| # Wait for send_data_interval or until stop/error event is set | |
| if await self._wait_for_interval(self.send_data_interval): | |
| break # Stop or error event was set, exit loop | |
| # Pull all available items from the data_queue | |
| data_items = [] | |
| while len(self.data_queue) > 0 and not self.stop_event.is_set() and not self.error_event.is_set(): | |
| data = self.data_queue.popleft() | |
| if data is None: | |
| # Sentinel value to stop loop | |
| if data_items: | |
| # Send any remaining items before stopping | |
| break | |
| else: | |
| return # No items to send, just stop | |
| else: | |
| data_items.append(data) | |
| # Send all collected data items | |
| if len(data_items) > 0: | |
| try: | |
| data_str = json.dumps(data_items) + "\n" | |
| except Exception as e: | |
| logger.error(f"Error serializing data items: {e}") | |
| continue | |
| await self.protocol.publish_data(data_str) | |
| except Exception as e: | |
| logger.error(f"Error in data sending loop: {e}") |
We could write additional tests to validate performance of the data publisher code path in client.py
I think we should wrap this in a try/except block as well, and should allow us to remove the check for the queue length.
Originally posted by @pschroedl in #25 (comment)
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request