[QUESTION] uvicorn can't reload when i use apscheduler and fastapi together
See original GitHub issuewhen i use apscheduler and fastapi together like this:
def get_app():
app = FastAPI()
return app
def apscheduler():
scheduler = AsyncIOScheduler()
scheduler.add_job(my_jobs.tick, 'cron', hour=2, minute=0)
deadline = datetime.datetime.now().replace(microsecond=0) + datetime.timedelta(seconds=5)
scheduler.add_job(my_jobs.tick, 'date', run_date=deadline)
try:
scheduler.start()
except Exception as e:
scheduler.shutdown()
apscheduler()
app = get_app()
uvicorn can’t reload automaticly like before here is my start command:
uvicorn main:app --reload
Thank you very much if anyone can help.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10 (1 by maintainers)
Top Results From Across the Web
FastAPI reload stops during reload - gunicorn - Stack Overflow
and the API seems to not be changing when it runs, still operating in the state the server started.
Read more >uvicorn - Reddit post and comment search - SocialGrep
I have developed a fastAPI application which is served via gunicorn with uvicorn workers. We noticed that APScheduler (AsycIOScheduler) is working with uvicorn...
Read more >FastAPI in Containers - Docker
Build a Docker Image with a Single-File FastAPI Then adjust the Uvicorn command to use the new module main instead of app. main...
Read more >Software Packages in "jammy", Subsection python - Ubuntu
Construct, convert, and manipulate colors in a Pythonic manner. python3-colour (0.1.5-2) [universe]: converts and manipulates various color representation - ...
Read more >Browse Python Technical Problem Clusters - Code Grepper
warning: there was an error checking the latest version of pip. conda install fastapi · modulenotfounderror: no module named 'png' · iterate over...
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
@anne17 That’s a perfect use of
app.state
😃 IMO this is a better practice than initializing everything at import time in the module scope, as recommended in the docs.For me it worked to shut down the scheduler in the shutdown event as suggested by @selimb. I am not sure at all if this is best practice, but I store the scheduler in
app.state
in the startup event and then I can access it later:Now uvicorn’s
--reload
works as it should.