Skip to content

[BUG] repeat_every now blocks application startup #307

@gabriel-faria-zipline

Description

@gabriel-faria-zipline

Describe the bug
On v.0.6.0 the @repeat_every will prevent the application from starting up.

To Reproduce
A simple @repeat_every implementation:

import logging
from contextlib import asynccontextmanager

import uvicorn
from fastapi import FastAPI
from fastapi_utils.tasks import repeat_every

logging.basicConfig(level=logging.INFO, force=True)
logger = logging.getLogger(__name__)


@asynccontextmanager
async def lifespan(app: FastAPI):
    await do_something()
    yield


app = FastAPI(lifespan=lifespan)


@repeat_every(seconds=1, logger=logger)
async def do_something() -> None:
    logger.info("REPETITION EXECUTED.")
    return


@app.get("/")
async def health():
    return 'Success'


if __name__ == "__main__":
    uvicorn.run(app, host="localhost", port=8080)

Expected behavior
The app starts showing: (which works on v0.2.0

$ python main.py                                        
INFO:     Started server process [4160]
INFO:     Waiting for application startup.
INFO:__main__:REPETITION EXECUTED.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://localhost:8080 (Press CTRL+C to quit)
INFO:__main__:REPETITION EXECUTED.

But in v0.6.0 the server is blocked by repeat_every execution:

$ python main.py                                          
INFO:     Started server process [4223]
INFO:     Waiting for application startup.     <<<< It never gets past this
INFO:__main__:REPETITION EXECUTED.

Environment:

  • OS: MacOs
>>> print(fastapi_utils.__version__)
0.6.0
>>> print(fastapi.__version__)
0.111.0
>>> print(pydantic.utils.version_info())
             pydantic version: 1.10.15
            pydantic compiled: False
                 install path: /opt/homebrew/lib/python3.12/site-packages/pydantic
               python version: 3.12.2 (main, Feb  6 2024, 20:19:44) [Clang 15.0.0 (clang-1500.1.0.2.5)]
                     platform: macOS-14.5-arm64-arm-64bit
     optional deps. installed: ['dotenv', 'email-validator', 'typing-extensions']

Python 3.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions