Conversation
The _communicator thread was never signalled to stop, so cleanup() closed the serial port while the thread kept polling ser.in_waiting on the dead file descriptor, raising OSError: [Errno 9] Bad file descriptor. cleanup() now sets thread_end and joins the thread before ser.close(). Also move thread_end and msg_queue from class attributes to instance attributes: as class attributes they were shared process-wide, so a second Arduino instance would inherit an already-set thread_end and its communicator would exit immediately. The class-level callbacks=True was dead code, always shadowed by the instance attribute set in Interface.__init__. The communicator thread is now a daemon, so if a wedged readline() ever makes the join time out, the leftover thread cannot block interpreter shutdown. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix Arduino serial shutdown race
Arduino.cleanup()closed the serial port while the background communicator thread was still running, so the thread could hit a closed port mid-read and raise on exit.Changes
cleanup()now signalsthread_end, joins the communicator thread with a 2 second timeout, and only then closes the serial connection. A warning is logged if the thread does not stop in time.thread_endandmsg_queuemoved from class attributes to instance attributes in__init__. As class attributes they were shared across everyArduinoinstance, meaning one instance's cleanup would stop another's thread.callbacks = Trueclass attribute, which shadowed the value the baseInterfacealready sets from its constructor argument.Files
src/ethopy/interfaces/Arduino.py