Compare commits
2 Commits
main
...
feat/error
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ca58f9486 | ||
|
|
711f4a3e60 |
@ -4,8 +4,6 @@ Use the following options to configure Uvicorn, when running from the command li
|
||||
|
||||
If you're running programmatically, using `uvicorn.run(...)`, then use
|
||||
equivalent keyword arguments, eg. `uvicorn.run("example:app", port=5000, reload=True, access_log=False)`.
|
||||
Please note that in this case, if you use `reload=True` or `workers=NUM`,
|
||||
you should put `uvicorn.run` into `if __name__ == '__main__'` clause in the main module.
|
||||
|
||||
You can also configure Uvicorn using environment variables with the prefix `UVICORN_`.
|
||||
For example, in case you want to run the app on port `5000`, just set the environment variable `UVICORN_PORT` to `5000`.
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import multiprocessing
|
||||
import os
|
||||
import platform
|
||||
import ssl
|
||||
@ -569,13 +570,17 @@ def run(
|
||||
)
|
||||
server = Server(config=config)
|
||||
|
||||
if (config.reload or config.workers > 1) and not isinstance(app, str):
|
||||
is_main_process = multiprocessing.current_process().name == "MainProcess"
|
||||
# fmt: off
|
||||
if (config.reload or config.workers > 1) and not isinstance(app, str) or not is_main_process: # noqa
|
||||
logger = logging.getLogger("uvicorn.error")
|
||||
logger.warning(
|
||||
"You must pass the application as an import string to enable 'reload' or "
|
||||
"'workers'."
|
||||
)
|
||||
if not isinstance(app, str):
|
||||
msg = "You must pass the application as an import string to enable 'reload' or 'workers'." # noqa: E501
|
||||
elif not is_main_process:
|
||||
msg = "You must run `uvicorn.run()` inside a `if __name__ == '__main__'` block." # noqa: E501
|
||||
logger.error(msg)
|
||||
sys.exit(1)
|
||||
# fmt: on
|
||||
|
||||
if config.should_reload:
|
||||
sock = config.bind_socket()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user