Fix parallelism not working

This commit is contained in:
Andras Schmelczer 2022-07-13 12:45:11 +02:00
parent 1dcf5bb3af
commit 03765e1aca
No known key found for this signature in database
GPG key ID: 0EA1BC97D0AB076E

View file

@ -10,7 +10,7 @@ from typing import Optional
import uvicorn import uvicorn
from uvicorn._subprocess import get_subprocess from uvicorn._subprocess import get_subprocess
from uvicorn.config import LOGGING_CONFIG, Config from uvicorn.config import LOGGING_CONFIG, Config
from uvicorn.supervisors.basereload import BaseReload from uvicorn.supervisors import BaseReload, Multiprocess
from watchdog.events import FileSystemEvent, PatternMatchingEventHandler from watchdog.events import FileSystemEvent, PatternMatchingEventHandler
from watchdog.observers import Observer from watchdog.observers import Observer
@ -68,15 +68,13 @@ def serve() -> None:
config = Config(app, **common_config) config = Config(app, **common_config)
socket = config.bind_socket() socket = config.bind_socket()
server = GreatAIReload(
config, target=uvicorn.Server(config=config).run, sockets=[socket]
)
server.startup()
try: try:
Event().wait() Multiprocess(
config, target=uvicorn.Server(config=config).run, sockets=[socket]
).run()
finally: finally:
server.shutdown()
if args.file_name.endswith(".ipynb"): if args.file_name.endswith(".ipynb"):
Path(get_script_name_of_notebook(args.file_name)).unlink( Path(get_script_name_of_notebook(args.file_name)).unlink(
missing_ok=True missing_ok=True