Does having hotkeys take an async function make sense? #298
-
New to asyncio stuff, but does having |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The callback is simply a callable. Although an async function is technically a callable, calling an async function merely produces a coroutine which must be awaited, so this is likely not what you want to do. If you must call an async function for your callback, you can use different strategies to work around this, (for example, calling Without knowing exactly what your code looks like, a simple solution might be to do something like this:
Keep in mind that hotkey callbacks each run in their own thread, anyhow. |
Beta Was this translation helpful? Give feedback.
The callback is simply a callable. Although an async function is technically a callable, calling an async function merely produces a coroutine which must be awaited, so this is likely not what you want to do.
If you must call an async function for your callback, you can use different strategies to work around this, (for example, calling
asyncio.run
in a regular function) but ultimately, you want to be passing a regular function toahk.add_hotkey
.Without knowing exactly what your code looks like, a simple solution might be to do something like this: