-
Notifications
You must be signed in to change notification settings - Fork 24
Add callable stop flag to EventListener class
#49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
jsiegle
commented
Nov 6, 2025
- Merge changes from add callable stop flag to event listener #48
- Increment version to 1.0.1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a callable stop() method to the EventListener class, allowing programmatic stopping of the event listener from another thread instead of relying solely on ctrl-C. The version is incremented to 1.0.1.
- Added a
runningflag to control the event listener loop - Implemented a
stop()method to set the flag to False - Enhanced error handling with a generic exception catch block
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/open_ephys/streaming/event_listener.py | Added running flag, stop() method, and improved exception handling |
| src/open_ephys/streaming/README.md | Updated documentation to mention the new stop() method |
| src/open_ephys/init.py | Incremented version from 1.0.0 to 1.0.1 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| print("EventListener stopped.") | ||
| print("") |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 143-144 are incorrectly indented and will execute on every loop iteration instead of only when the loop exits. These lines should be dedented to align with the while statement so they execute after the loop completes.
| print("EventListener stopped.") | |
| print("") | |
| print("EventListener stopped.") | |
| print("") |
| print("Stopped by KeyboardInterrupt") # Add final newline | ||
| break | ||
| except Exception as e: | ||
| print(f"Error: {e}") |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The generic exception handler catches and prints errors but doesn't break the loop or stop execution. This could mask critical errors and cause the listener to continue running in an invalid state. Consider whether certain exceptions should stop the listener or if the exception should be re-raised after logging.
| print(f"Error: {e}") | |
| print(f"Error: {e}") | |
| raise |
| self.socket = self.context.socket(zmq.SUB) | ||
| self.socket.connect(self.url) | ||
| self.socket.setsockopt(zmq.SUBSCRIBE, b"") | ||
| self.running = False # Stop flag |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The running flag should be thread-safe since the documentation indicates stop() will be called from another thread. Consider using threading.Event or marking this as an atomic operation with appropriate synchronization to prevent race conditions.