Fix: join the control thread before closing the CAN socket - #81
Open
tendant wants to merge 1 commit into
Open
Conversation
DMChainCanInterface.close() sets running = False and closes the CAN socket in
the same breath, without waiting for the control loop to notice:
def close(self) -> None:
self.running = False
self.motor_interface.close()
A thread already inside _set_commands then sends on a socket that has just
been closed, and dies on every clean shutdown:
Robot closed with all torques set to zero.
ERROR:root:1th motor at DMChainCanInterface(channel=can0) failed with info [2, 'DM4340']
DM Error in control loop: file descriptor cannot be a negative integer (-1)
Exception in thread Thread-1 (_set_torques_and_update_state):
File "i2rt/motor_drivers/can_interface.py", line 54, in _send_message_get_response
self.bus.send(message)
ValueError: file descriptor cannot be a negative integer (-1)
It could not be joined, because start_thread() assigned the handle to a local
and dropped it. Keep it, and join it in close() with a timeout so close()
stays bounded if the loop is wedged — in that case behaviour is unchanged.
MotorChainRobot.close() already does this for its own thread one level up, so
this brings the motor chain in line with the pattern beside it.
Cosmetic: it fires after torques are zeroed, so the arm is safe either way.
But it is noisy enough to bury anything else printed around a shutdown, and it
reproduces on every disconnect — including a plain connect/read/disconnect
with no motion commanded.
Co-Authored-By: Claude Opus 5 (1M context) <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.
DMChainCanInterface.close() sets running = False and closes the CAN socket in the same breath, without waiting for the control loop to notice:
A thread already inside _set_commands then sends on a socket that has just been closed, and dies on every clean shutdown:
It could not be joined, because start_thread() assigned the handle to a local and dropped it. Keep it, and join it in close() with a timeout so close() stays bounded if the loop is wedged — in that case behaviour is unchanged.
MotorChainRobot.close() already does this for its own thread one level up, so this brings the motor chain in line with the pattern beside it.
Cosmetic: it fires after torques are zeroed, so the arm is safe either way. But it is noisy enough to bury anything else printed around a shutdown, and it reproduces on every disconnect — including a plain connect/read/disconnect with no motion commanded.