Replies: 5 comments 3 replies
-
does it happen without docker ? |
Beta Was this translation helpful? Give feedback.
-
@euri10 It looks all right without docker. |
Beta Was this translation helpful? Give feedback.
-
You mean that you are doing CTRL + C multiple times? If that's the case, then it's normal... |
Beta Was this translation helpful? Give feedback.
-
@Kludex I mean that I repeat these operations - [docker run ..., wait for a moment, ..., press CTRL + C] many times. rather than repeating these opertions - docker run, ..., wait for a moment, then only press CTRL + C many times. |
Beta Was this translation helpful? Give feedback.
-
I reproduce the same error every time, with or without docker, but only with from multiprocessing import Process
from fastapi import FastAPI
from contextlib import asynccontextmanager
import time
class MyP(Process):
def __init__(self):
super().__init__()
def run(self):
while True:
print('foo')
time.sleep(1)
print('finished')
@asynccontextmanager
async def lifespan(app):
myp = MyP()
myp.start()
from asyncio.exceptions import CancelledError
try:
yield
except CancelledError:
print('Got CancelledError, exiting')
myp.terminate()
myp.join()
app = FastAPI(
title="demo that hangs when you ctrl+c",
description="""
""",
lifespan=lifespan,
)
@app.get("/")
def hello_world():
return {"hello": "world!"}
if __name__ == '__main__':
myp = MyP()
myp.start()
time.sleep(5)
myp.terminate()
myp.join() When executing directly with When executing with When executing with Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
My test code shown below:
% ls
Dockerfile test.py
And then build an image in my work directory:
docker build -t test-uvicorn:20220916 .
Start docker container using the command shown below:
Wait for a moment, and then press CTRL + C, Maybe get outputs like below:
when I repeat these operations many times, The above error will occur occasionally.
Beta Was this translation helpful? Give feedback.
All reactions