-
-
Notifications
You must be signed in to change notification settings - Fork 777
Open
Description
Discovered this by accident today: the following works:
@hookimpl
async def startup(datasette):
await asyncio.sleep(0.1)
print("Startup hook fired")
I had previously thought you needed to do this instead:
@hookimpl
def startup(datasette):
async def inner():
await asyncio.sleep(0.1)
print("Startup hook fired")
return inner
It turns out Pluggy (at least up to 1.6.0 the current version) doesn't feature the keywords asyncio
or await
anywhere in the codebase... but the above works anyway because Pluggy ends up returning a coroutine that needs to be awaited and Datasette then does this:
Lines 591 to 592 in 7a60214
for hook in pm.hook.startup(datasette=self): | |
await await_me_maybe(hook) |
And await_me_maybe()
does the right thing with that coroutine that Pluggy returned!