objects defining async __call__ not run/awaited when used in on_startup
See original GitHub issueSimple reproducer:
def test_async_startup_hangs():
class Foo:
async def __call__(self):
raise Exception()
app = Starlette(on_startup=[Foo()])
with TestClient(app) as client:
pass
No exception is raised when it should be. This, however, raises an exception as expected:
def test_async_startup_hangs():
async def foo():
raise Exception()
app = Starlette(on_startup=[foo])
with TestClient(app) as client:
pass
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (11 by maintainers)
Top Results From Across the Web
Async OnStartup in a WPF application - Stack Overflow
You can call async Methods from within a synchronous method like this: YourAsyncMethod().Wait();. So you can make your OnStartup-Method ...
Read more >async function - JavaScript - MDN Web Docs - Mozilla
Use of async and await enables the use of ordinary try / catch blocks around asynchronous code. Note: The await keyword is only...
Read more >Async/Await - Best Practices in Asynchronous Programming
When an exception is thrown out of an async Task or async Task<T> method, that exception is captured and placed on the Task...
Read more >Built in options for running async tasks
In this post I look at the problem of running one-off tasks asynchronously on app startup in ASP.NET Core, and explore the pros...
Read more >Is there a reason why I should not call an Async method from ...
But I've not been able to find a reference to… ... public override async void OnStart() { await ... Use async Task instead....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
TBH I’d be quite keen to moving Starlette towards always expecting an
async
style on endpoints, startup/shutdown functions, error handlers etc.Users could still use sync style functions, but we’d require them to be explicitly wrapped in a threadpooling
sync -> async
decorator.Turns out this issue also affects partial:
https://stackoverflow.com/questions/52422860/partial-asynchronous-functions-are-not-detected-as-asynchronous
@tomchristie suggested Starlette should grow its own function to make these checks, once that’s happened, we should see about pushing it back into CPython core.