Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't call rpc_request from event callbacks #3

Open
murilopolese opened this issue Aug 23, 2018 · 2 comments
Open

Can't call rpc_request from event callbacks #3

murilopolese opened this issue Aug 23, 2018 · 2 comments
Labels
bug Something isn't working help wanted Extra attention is needed python Python SDK

Comments

@murilopolese
Copy link
Contributor

Can't get event loop from inside a coroutine, apparently. I have no idea how to fix this and it's probably because I should be doing this in a different way.

This code:

from communitysdk import list_connected_devices, MotionSensorKit
msk = None
devices = list_connected_devices()
if len(devices):
    if isinstance(devices[0], MotionSensorKit):
        msk = devices[0]
        def on_proximity(p):
            if p > 200:
                try:
                    msk.set_mode('proximity')
                except Exception as e:
                    print(e)
            else:
                print('proximity', p)
        def on_gesture(g):
            if g == 'up':
                try:
                    msk.set_mode('proximity')
                except Exception as e:
                    print(e)
            else:
                print('gesture', g)
        msk.on_proximity = on_proximity
        msk.on_gesture = on_gesture
else:
    print('there is no device connected')

Prints There is no current event loop in thread 'ThreadPoolExecutor-0_0'. when I swipe up on Motion Sensor.

@murilopolese
Copy link
Contributor Author

While not a perfect solution because introduce a race condition, removing the creation of a coroutine for waiting the response makes it possible to call rpc_request from a method called from the Executor. The rpc_request was always meant to be blocking so instead of running it on the asyncio thread it's actually running on the main thread.

For requests that require a faster rate, such as stream_frame it doesn't use the blocking rpc_request but sends the data straight to the connection.

c74dcff

@murilopolese
Copy link
Contributor Author

murilopolese commented Aug 29, 2018

As the result of the race condition apparently behaves inconsistently on different computers (might be the specs or the OS) this turns out to be a terrible idea. Reopening this issue and going to try a different approach like this or this.

@murilopolese murilopolese reopened this Aug 29, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed python Python SDK
Projects
None yet
Development

No branches or pull requests

1 participant