Skip to content

Errors in async callbacks are silently swallowed (easily fixed, happy to send a PR) #172

@egnor

Description

@egnor

Describe the bug
If an async callback registered with set_key_callback_async() throws an exception -- even a runtime exception -- the error is silently swallowed. (This applies to other async callback types as well, eg. dial callbacks.) This skips any asyncio exception handler that may have been registered. As you can imagine this can be quite confusing because a little typo or whatever causes strange silent failure.

This is because the line where the callback is dispatched to the event loop discards the resulting Future:

asyncio.run_coroutine_threadsafe(async_callback(*args), loop)

This could be fixed by taking the result of loop.run_coroutine_threadsafe and then calling .add_done_callback() on it to log or otherwise handle the error, OR, by using loop.call_soon_threadsafe instead and having it use loop.create_task to invoke the callback (the Task will use the system exception reporting as usual).

To Reproduce
Register an async callback that raises an exception of any type. Run the program, see no errors -- it just keeps running, and the callback in question silently stops at the point of error.

StreamDeck Information
(Applies to all StreamDeck models.)

System Information
(Applies to all OS. I am using library 0.9.8 and it seems to be the case at github head as well.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions