-
-
Notifications
You must be signed in to change notification settings - Fork 422
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
Notify call no more working in 0.9.4 and newer with fastapi events #610
Comments
Hmm, I'm stumped with this one; i'd be open to any advice here from anyone else. I can certainly reproduce the problem, but nothing changed with the This is definitely a good bug.... 😕 python ../try_fail.py Produces:
I need a try/catch block around here. However when a loop is already running, i can't seem to find any good documentation on how to execute the coroutine in a blocking state so we can get the response. There seems to be reference to getting the nest-asyncio library to help. I'm not sure here... Maybe @YoRyan has an idea here? |
As an update, this seems to work: # services/users/project/try_fail.py
import uvicorn
import apprise
from fastapi import FastAPI
import nest_asyncio
app = FastAPI(
title="apprise_failure",
description="A sample",
)
@app.on_event("startup")
def system_startup():
apobj = apprise.Apprise()
apobj.notify(body = "Application Startup", title = "startup failed")
print("passed !")
def main():
nest_asyncio.apply()
uvicorn.run(
"try_fail:app",
host="0.0.0.0",
port=9000,
reload=True,
reload_dirs=["."],
debug=True,
log_level='debug',
log_config=None,
workers=1,
forwarded_allow_ips="*",
)
if __name__ == "__main__":
main() I only added 2 lines after running the following: pip install nest-asyncio
|
I see you changed the title 9hrs, ago. Were you able to try my modification to your sample code? That may resolve your issue. |
Hi. |
Great idea! I added a section here in Troubleshooting and also beefed up the documentation a bit here to explain how you can also leverage This should address your documentation request? Thoughts? |
yes, perfect ! thx to you |
If a framework has its own async event loop, it should also accept async handlers. So this works without requiring nest_asyncio: @app.on_event("startup")
async def system_startup():
apobj = apprise.Apprise()
await apobj.async_notify(body = "Application Startup", title = "startup failed")
print("passed !") It's a shame we've broken existing code, but fortunately, the fix should be simple: If running in an existing event loop, switch to the new async_notify() method. |
try this sample application:
This application works well with apprise 0.9.3 but does not work anymore with 0.9.4 and more recent versions.
You may use any recent version of fastapi and uvicorn.
The text was updated successfully, but these errors were encountered: