anki / cozmo-python-sdk

Anki Cozmo Python SDK
Other
662 stars 430 forks source link

COZMO-7331 Ensure sync connect calls use same loop #141

Closed gwatts closed 7 years ago

gwatts commented 7 years ago

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)