Refactor FastAPI server launch to use multiprocessing for improved performance
Browse files
app.py
CHANGED
@@ -35,8 +35,12 @@ def wait_for_fastapi(timeout=30, interval=0.5):
|
|
35 |
return False
|
36 |
|
37 |
# Run FastAPI server in a separate thread
|
|
|
|
|
38 |
def run_fastapi():
|
39 |
-
|
|
|
|
|
40 |
|
41 |
# Start FastAPI in a background thread
|
42 |
fastapi_thread = threading.Thread(target=run_fastapi, daemon=True)
|
|
|
35 |
return False
|
36 |
|
37 |
# Run FastAPI server in a separate thread
|
38 |
+
#def run_fastapi():
|
39 |
+
# uvicorn.run(fastapi_app, host="0.0.0.0", port=7860)
|
40 |
def run_fastapi():
|
41 |
+
import multiprocessing
|
42 |
+
multiprocessing.Process(target=uvicorn.run, args=(fastapi_app,), kwargs={"host": "0.0.0.0", "port": 7860}).start()
|
43 |
+
|
44 |
|
45 |
# Start FastAPI in a background thread
|
46 |
fastapi_thread = threading.Thread(target=run_fastapi, daemon=True)
|