Skip to content

Commit

Permalink
experiment with more complete copy of uvicorn.run
Browse files Browse the repository at this point in the history
  • Loading branch information
falkoschindler committed Sep 13, 2022
1 parent ecf4841 commit 501323d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions nicegui/run.py
Expand Up @@ -2,11 +2,12 @@
import logging
import os
import sys
import typing
import webbrowser
from typing import List, Optional

import uvicorn
from uvicorn.main import STARTUP_FAILURE
from uvicorn.supervisors import ChangeReload, Multiprocess

from . import globals
from .config import Config
Expand All @@ -31,7 +32,24 @@ def split_args(args: str) -> List[str]:
log_level=config.uvicorn_logging_level,
)
globals.server = uvicorn.Server(config=config)
globals.server.run()

if (config.reload or config.workers > 1) and not isinstance(config.app, str):
logging.warning('You must pass the application as an import string to enable "reload" or "workers".')
sys.exit(1)

if config.should_reload:
sock = config.bind_socket()
ChangeReload(config, target=globals.server.run, sockets=[sock]).run()
elif config.workers > 1:
sock = config.bind_socket()
Multiprocess(config, target=globals.server.run, sockets=[sock]).run()
else:
globals.server.run()
if config.uds:
os.remove(config.uds) # pragma: py-win32

if not globals.server.started and not config.should_reload and config.workers == 1:
sys.exit(STARTUP_FAILURE)


if globals.pre_evaluation_succeeded and globals.config.reload and not inspect.stack()[-2].filename.endswith('spawn.py'):
Expand Down

0 comments on commit 501323d

Please sign in to comment.