Python Script with Odrive not exiting

I’m running a Python script (from the command line on Raspberry Pi 4) that connects to an Odrive, but the script fails to exit upon completion. In order to end the task, I need to provide a Keyboard Exception which will then output:

pi@raspberrypi: $ sudo python3 testy.py

Found an odrive!
Bus voltage is: 48.1424560546875
^CException ignored in: <module ‘threading’ from ‘/usr/lib/python3.7/threading.py’>
Traceback (most recent call last):
File “/usr/lib/python3.7/threading.py”, line 1281, in _shutdown
t.join()
File “/usr/lib/python3.7/threading.py”, line 1032, in join
self._wait_for_tstate_lock()
File “/usr/lib/python3.7/threading.py”, line 1048, in _wait_for_tstate_lock
elif lock.acquire(block, timeout):
KeyboardInterrupt

The testy.py script is:

import odrive
odrv0 = odrive.find_any(timeout=5)
if str(odrv0) == “None”:
print(“Didn’t find an odrive :(”)
else:
print(“Found an odrive!”)
print("Bus voltage is: ", str(odrv0.vbus_voltage))

I’d expect this script to connect to the odrive, run the if statement, and end the script once the end is reached, not hang as it currently is.

Huh. Weird. It should just exit. @Samuel will have to investigate

This was a bug in older versions of the odrive Python package and was fixed. Your example script exits normally for me. Try upgrading with sudo pip3 install --upgrade odrive.