core icon indicating copy to clipboard operation
core copied to clipboard

[BUG] Startup process processed twice

Open sambarza opened this issue 1 year ago • 2 comments

Describe the bug The startup process in main.py is being executed twice.

To Reproduce

  1. Add print("STARTING", __name__) in the main.py file just after the imports
  2. Run the application
  3. In the console you should see the following:
cheshire_cat_core  | STARTING __main__
cheshire_cat_core  | STARTING cat.main

Additional context uvicorn.run() is importing main.py again, causing the startup process to be triggered twice:

    uvicorn.run(
        "cat.main:cheshire_cat_api",
        host="0.0.0.0",
        port=80,
        use_colors=True,
        log_level=get_env("CCAT_LOG_LEVEL").lower(),
        **debug_config,
        **proxy_pass_config,
    )

sambarza avatar Oct 03 '24 20:10 sambarza

Should we change with fastapi-cli??

valentimarco avatar Oct 03 '24 21:10 valentimarco

Maybe something simpler, just move the cheshire_cat_api FastAPI initialization to a separate file, and keep only the uvicorn.run in main.

Something like this? https://github.com/sambarza/test-fastapi-cors

sambarza avatar Oct 03 '24 23:10 sambarza

Thanks never realized it was running twice XD

pieroit avatar Oct 04 '24 10:10 pieroit

Merging soon

pieroit avatar Oct 21 '24 18:10 pieroit