Skip to content
Discussion options

You must be logged in to vote

As JavierSanchezCastro mentioned, it comes from Uvicorn (Kludex/uvicorn#1301).

The solution from here is to set the handler for SIGINT signal:

import asyncio
from contextlib import asynccontextmanager
import logging
import signal
import sys

from fastapi import FastAPI

logger = logging.getLogger("uvicorn")

def receive_signal(signalNumber, frame):
    print("Received:", signalNumber)
    sys.exit()

@asynccontextmanager
async def lifespan(app: FastAPI):
    signal.signal(signal.SIGINT, receive_signal)
    logger.info("Starting up...")
    for i in range(10):
        logger.info(f"long process running ({i})...")
        await asyncio.sleep(1)
    yield
    logger.info("Shutdown...")


app = 

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@Xmaster6y
Comment options

@JavierSanchezCastro
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by YuriiMotov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem
3 participants