How to start background_tasks on event startup
See original GitHub issue@app.on_event("startup")
async def startup_event(background_tasks: BackgroundTasks):
send_notification(background_tasks)
2021-05-12 15:31:40,350 - MainThread - ERROR - Traceback (most recent call last):
File "F:\douyin_spider_fast_api\venv\lib\site-packages\starlette\routing.py", line 540, in lifespan
async for item in self.lifespan_context(app):
File "F:\douyin_spider_fast_api\venv\lib\site-packages\starlette\routing.py", line 481, in default_lifespan
await self.startup()
File "F:\douyin_spider_fast_api\venv\lib\site-packages\starlette\routing.py", line 516, in startup
await handler()
TypeError: startup_event() missing 1 required positional argument: 'background_tasks'
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:10
Top Results From Across the Web
Background Tasks - FastAPI
You can define background tasks to be run after returning a response. This is useful for operations that need to happen after a...
Read more >Create and register an in-process background task
Create and register an in-process task that runs in the same process as your foreground app.
Read more >Start an async background daemon in a Python FastAPI app
try @app.on_event("startup") async def startup_event() -> None: """tasks to do at server startup""" ...
Read more >Using background tasks to update your app - Apple Developer
To schedule a task to run in the background, enable the background modes in Xcode, identify the specific tasks that you need, and...
Read more >How to run background tasks in ASP.NET Core Application
Background tasks using IHostedService · Firstly, the StartAsync method is called by the framework before the Configure method of the Startup ...
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
@codemation That is an issue in my opinion. on_event(‘startup’) does not mean that you will always want to call a method without arguments on startup, does it?
In any case, a workaround to be able to start a background task on startup is highly appreciated. I haven’t found a way to do so yet.
The most obvious way to achieve referencing your method that takes arguments, is with a new method with the arguments statically defined:
@tusharjagtap-bc It might help if you share what argument that you are passing into your startup event.