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
How to use callback async? #492
Comments
Callbacks are executed in the same thread, sequentially, so two callbacks with 5 seconds of sleep each result in one long thread sleeping 10 seconds. Asyncio may have helped if you were not using The easiest solution is to spawn a new thread on each callback, so that they can sleep separately. You use # pip install keyboard
from keyboard import add_hotkey, wait, call_later
from time import sleep
def on_callback(key):
print('pressed', key)
sleep(5)
print('end for', key)
add_hotkey("f4", lambda: call_later(on_callback, args=("f4",)))
add_hotkey("f8", lambda: call_later(on_callback, args=("f8",)))
wait('esc') |
|
The However I'm not sure it'll play well with the rest of |
Yeah,
In my case, async didn't happen add_hotkey(item["keys"], lambda: asyncio.run(_on_callback(item["function"])))
async def _on_callback(function):
response = await _script.run(function)
async def run(self, function: str):
# ...
return self.service.run(scriptId=self._id, body=body) |
Need to register global hotkeys. For example,
f4
andf8
. Withkeyboard
library while first callback didn't return, the next won't call.Another words, logs like this
But I want to like this
Demo code
I tried to use
asyncio
, but nothing changedThe text was updated successfully, but these errors were encountered: