Creating a new loop for every call to _connect_sync breaks the default
connector instance, which maintains a connection to usbmuxd using the
loop first available to it. This prevents subsequent calls to connect
from succeeding for synchronous functions.
Instead allocate a loop for synchronous code up front and re-use that
for any subsequent sync calls.
Simple test that will fail prior to this update:
import sys
import cozmo
def run(sdk_conn):
'''The run method runs once Cozmo is connected.'''
robot = sdk_conn.wait_for_robot()
if __name__ == '__main__':
cozmo.setup_basic_logging()
cozmo.connect(run)
cozmo.connect(run)
Creating a new loop for every call to _connect_sync breaks the default connector instance, which maintains a connection to usbmuxd using the loop first available to it. This prevents subsequent calls to connect from succeeding for synchronous functions.
Instead allocate a loop for synchronous code up front and re-use that for any subsequent sync calls.
Simple test that will fail prior to this update: