We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Docs: workers = 1 when WEB_CONCURRENCY is not set
Hello, thanks for this great ASGI server 🙂 

I have an application that must use only one worker (it's not thread-safe), and so I wanted to confirm that, by default, uvicorn only uses one worker. But I had to read the source code

https://github.com/encode/uvicorn/blob/afb2d565c8dae859bcef4c76b3c6dc3f3077314d/uvicorn/config.py#L177

...to confirm that when `WEB_CONCURRENCY` is not defined, and `workers` is not specified, 1 is used.

Would you accept a PR adding that information to the docs (there are 4-5 places where this can be added)?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `uvicorn/main.py`
Content:
```
1 import logging
2 import platform
3 import ssl
4 import sys
5 import typing
6 
7 import click
8 
9 import uvicorn
10 from uvicorn.config import (
11     HTTP_PROTOCOLS,
12     INTERFACES,
13     LIFESPAN,
14     LOG_LEVELS,
15     LOGGING_CONFIG,
16     LOOP_SETUPS,
17     SSL_PROTOCOL_VERSION,
18     WS_PROTOCOLS,
19     Config,
20 )
21 from uvicorn.server import Server, ServerState  # noqa: F401  # Used to be defined here.
22 from uvicorn.supervisors import ChangeReload, Multiprocess
23 
24 LEVEL_CHOICES = click.Choice(LOG_LEVELS.keys())
25 HTTP_CHOICES = click.Choice(HTTP_PROTOCOLS.keys())
26 WS_CHOICES = click.Choice(WS_PROTOCOLS.keys())
27 LIFESPAN_CHOICES = click.Choice(LIFESPAN.keys())
28 LOOP_CHOICES = click.Choice([key for key in LOOP_SETUPS.keys() if key != "none"])
29 INTERFACE_CHOICES = click.Choice(INTERFACES)
30 
31 logger = logging.getLogger("uvicorn.error")
32 
33 
34 def print_version(ctx, param, value):
35     if not value or ctx.resilient_parsing:
36         return
37     click.echo(
38         "Running uvicorn %s with %s %s on %s"
39         % (
40             uvicorn.__version__,
41             platform.python_implementation(),
42             platform.python_version(),
43             platform.system(),
44         )
45     )
46     ctx.exit()
47 
48 
49 @click.command()
50 @click.argument("app")
51 @click.option(
52     "--host",
53     type=str,
54     default="127.0.0.1",
55     help="Bind socket to this host.",
56     show_default=True,
57 )
58 @click.option(
59     "--port",
60     type=int,
61     default=8000,
62     help="Bind socket to this port.",
63     show_default=True,
64 )
65 @click.option("--uds", type=str, default=None, help="Bind to a UNIX domain socket.")
66 @click.option(
67     "--fd", type=int, default=None, help="Bind to socket from this file descriptor."
68 )
69 @click.option(
70     "--debug", is_flag=True, default=False, help="Enable debug mode.", hidden=True
71 )
72 @click.option("--reload", is_flag=True, default=False, help="Enable auto-reload.")
73 @click.option(
74     "--reload-dir",
75     "reload_dirs",
76     multiple=True,
77     help="Set reload directories explicitly, instead of using the current working"
78     " directory.",
79 )
80 @click.option(
81     "--reload-delay",
82     type=float,
83     default=0.25,
84     show_default=True,
85     help="Delay between previous and next check if application needs to be."
86     " Defaults to 0.25s.",
87 )
88 @click.option(
89     "--workers",
90     default=None,
91     type=int,
92     help="Number of worker processes. Defaults to the $WEB_CONCURRENCY environment"
93     " variable if available. Not valid with --reload.",
94 )
95 @click.option(
96     "--loop",
97     type=LOOP_CHOICES,
98     default="auto",
99     help="Event loop implementation.",
100     show_default=True,
101 )
102 @click.option(
103     "--http",
104     type=HTTP_CHOICES,
105     default="auto",
106     help="HTTP protocol implementation.",
107     show_default=True,
108 )
109 @click.option(
110     "--ws",
111     type=WS_CHOICES,
112     default="auto",
113     help="WebSocket protocol implementation.",
114     show_default=True,
115 )
116 @click.option(
117     "--lifespan",
118     type=LIFESPAN_CHOICES,
119     default="auto",
120     help="Lifespan implementation.",
121     show_default=True,
122 )
123 @click.option(
124     "--interface",
125     type=INTERFACE_CHOICES,
126     default="auto",
127     help="Select ASGI3, ASGI2, or WSGI as the application interface.",
128     show_default=True,
129 )
130 @click.option(
131     "--env-file",
132     type=click.Path(exists=True),
133     default=None,
134     help="Environment configuration file.",
135     show_default=True,
136 )
137 @click.option(
138     "--log-config",
139     type=click.Path(exists=True),
140     default=None,
141     help="Logging configuration file. Supported formats: .ini, .json, .yaml.",
142     show_default=True,
143 )
144 @click.option(
145     "--log-level",
146     type=LEVEL_CHOICES,
147     default=None,
148     help="Log level. [default: info]",
149     show_default=True,
150 )
151 @click.option(
152     "--access-log/--no-access-log",
153     is_flag=True,
154     default=True,
155     help="Enable/Disable access log.",
156 )
157 @click.option(
158     "--use-colors/--no-use-colors",
159     is_flag=True,
160     default=None,
161     help="Enable/Disable colorized logging.",
162 )
163 @click.option(
164     "--proxy-headers/--no-proxy-headers",
165     is_flag=True,
166     default=True,
167     help="Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to "
168     "populate remote address info.",
169 )
170 @click.option(
171     "--forwarded-allow-ips",
172     type=str,
173     default=None,
174     help="Comma seperated list of IPs to trust with proxy headers. Defaults to"
175     " the $FORWARDED_ALLOW_IPS environment variable if available, or '127.0.0.1'.",
176 )
177 @click.option(
178     "--root-path",
179     type=str,
180     default="",
181     help="Set the ASGI 'root_path' for applications submounted below a given URL path.",
182 )
183 @click.option(
184     "--limit-concurrency",
185     type=int,
186     default=None,
187     help="Maximum number of concurrent connections or tasks to allow, before issuing"
188     " HTTP 503 responses.",
189 )
190 @click.option(
191     "--backlog",
192     type=int,
193     default=2048,
194     help="Maximum number of connections to hold in backlog",
195 )
196 @click.option(
197     "--limit-max-requests",
198     type=int,
199     default=None,
200     help="Maximum number of requests to service before terminating the process.",
201 )
202 @click.option(
203     "--timeout-keep-alive",
204     type=int,
205     default=5,
206     help="Close Keep-Alive connections if no new data is received within this timeout.",
207     show_default=True,
208 )
209 @click.option(
210     "--ssl-keyfile", type=str, default=None, help="SSL key file", show_default=True
211 )
212 @click.option(
213     "--ssl-certfile",
214     type=str,
215     default=None,
216     help="SSL certificate file",
217     show_default=True,
218 )
219 @click.option(
220     "--ssl-keyfile-password",
221     type=str,
222     default=None,
223     help="SSL keyfile password",
224     show_default=True,
225 )
226 @click.option(
227     "--ssl-version",
228     type=int,
229     default=SSL_PROTOCOL_VERSION,
230     help="SSL version to use (see stdlib ssl module's)",
231     show_default=True,
232 )
233 @click.option(
234     "--ssl-cert-reqs",
235     type=int,
236     default=ssl.CERT_NONE,
237     help="Whether client certificate is required (see stdlib ssl module's)",
238     show_default=True,
239 )
240 @click.option(
241     "--ssl-ca-certs",
242     type=str,
243     default=None,
244     help="CA certificates file",
245     show_default=True,
246 )
247 @click.option(
248     "--ssl-ciphers",
249     type=str,
250     default="TLSv1",
251     help="Ciphers to use (see stdlib ssl module's)",
252     show_default=True,
253 )
254 @click.option(
255     "--header",
256     "headers",
257     multiple=True,
258     help="Specify custom default HTTP response headers as a Name:Value pair",
259 )
260 @click.option(
261     "--version",
262     is_flag=True,
263     callback=print_version,
264     expose_value=False,
265     is_eager=True,
266     help="Display the uvicorn version and exit.",
267 )
268 @click.option(
269     "--app-dir",
270     "app_dir",
271     default=".",
272     show_default=True,
273     help="Look for APP in the specified directory, by adding this to the PYTHONPATH."
274     " Defaults to the current working directory.",
275 )
276 @click.option(
277     "--factory",
278     is_flag=True,
279     default=False,
280     help="Treat APP as an application factory, i.e. a () -> <ASGI app> callable.",
281     show_default=True,
282 )
283 def main(
284     app,
285     host: str,
286     port: int,
287     uds: str,
288     fd: int,
289     loop: str,
290     http: str,
291     ws: str,
292     lifespan: str,
293     interface: str,
294     debug: bool,
295     reload: bool,
296     reload_dirs: typing.List[str],
297     reload_delay: float,
298     workers: int,
299     env_file: str,
300     log_config: str,
301     log_level: str,
302     access_log: bool,
303     proxy_headers: bool,
304     forwarded_allow_ips: str,
305     root_path: str,
306     limit_concurrency: int,
307     backlog: int,
308     limit_max_requests: int,
309     timeout_keep_alive: int,
310     ssl_keyfile: str,
311     ssl_certfile: str,
312     ssl_keyfile_password: str,
313     ssl_version: int,
314     ssl_cert_reqs: int,
315     ssl_ca_certs: str,
316     ssl_ciphers: str,
317     headers: typing.List[str],
318     use_colors: bool,
319     app_dir: str,
320     factory: bool,
321 ):
322     sys.path.insert(0, app_dir)
323 
324     kwargs = {
325         "app": app,
326         "host": host,
327         "port": port,
328         "uds": uds,
329         "fd": fd,
330         "loop": loop,
331         "http": http,
332         "ws": ws,
333         "lifespan": lifespan,
334         "env_file": env_file,
335         "log_config": LOGGING_CONFIG if log_config is None else log_config,
336         "log_level": log_level,
337         "access_log": access_log,
338         "interface": interface,
339         "debug": debug,
340         "reload": reload,
341         "reload_dirs": reload_dirs if reload_dirs else None,
342         "reload_delay": reload_delay,
343         "workers": workers,
344         "proxy_headers": proxy_headers,
345         "forwarded_allow_ips": forwarded_allow_ips,
346         "root_path": root_path,
347         "limit_concurrency": limit_concurrency,
348         "backlog": backlog,
349         "limit_max_requests": limit_max_requests,
350         "timeout_keep_alive": timeout_keep_alive,
351         "ssl_keyfile": ssl_keyfile,
352         "ssl_certfile": ssl_certfile,
353         "ssl_keyfile_password": ssl_keyfile_password,
354         "ssl_version": ssl_version,
355         "ssl_cert_reqs": ssl_cert_reqs,
356         "ssl_ca_certs": ssl_ca_certs,
357         "ssl_ciphers": ssl_ciphers,
358         "headers": [header.split(":", 1) for header in headers],
359         "use_colors": use_colors,
360         "factory": factory,
361     }
362     run(**kwargs)
363 
364 
365 def run(app, **kwargs):
366     config = Config(app, **kwargs)
367     server = Server(config=config)
368 
369     if (config.reload or config.workers > 1) and not isinstance(app, str):
370         logger = logging.getLogger("uvicorn.error")
371         logger.warning(
372             "You must pass the application as an import string to enable 'reload' or "
373             "'workers'."
374         )
375         sys.exit(1)
376 
377     if config.should_reload:
378         sock = config.bind_socket()
379         supervisor = ChangeReload(config, target=server.run, sockets=[sock])
380         supervisor.run()
381     elif config.workers > 1:
382         sock = config.bind_socket()
383         supervisor = Multiprocess(config, target=server.run, sockets=[sock])
384         supervisor.run()
385     else:
386         server.run()
387 
388 
389 if __name__ == "__main__":
390     main()
391
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/uvicorn/main.py b/uvicorn/main.py
--- a/uvicorn/main.py
+++ b/uvicorn/main.py
@@ -90,7 +90,7 @@
     default=None,
     type=int,
     help="Number of worker processes. Defaults to the $WEB_CONCURRENCY environment"
-    " variable if available. Not valid with --reload.",
+    " variable if available, or 1. Not valid with --reload.",
 )
 @click.option(
     "--loop",

{"golden_diff": "diff --git a/uvicorn/main.py b/uvicorn/main.py\n--- a/uvicorn/main.py\n+++ b/uvicorn/main.py\n@@ -90,7 +90,7 @@\n     default=None,\n     type=int,\n     help=\"Number of worker processes. Defaults to the $WEB_CONCURRENCY environment\"\n-    \" variable if available. Not valid with --reload.\",\n+    \" variable if available, or 1. Not valid with --reload.\",\n )\n @click.option(\n     \"--loop\",\n", "issue": "Docs: workers = 1 when WEB_CONCURRENCY is not set\nHello, thanks for this great ASGI server \ud83d\ude42 \r\n\r\nI have an application that must use only one worker (it's not thread-safe), and so I wanted to confirm that, by default, uvicorn only uses one worker. But I had to read the source code\r\n\r\nhttps://github.com/encode/uvicorn/blob/afb2d565c8dae859bcef4c76b3c6dc3f3077314d/uvicorn/config.py#L177\r\n\r\n...to confirm that when `WEB_CONCURRENCY` is not defined, and `workers` is not specified, 1 is used.\r\n\r\nWould you accept a PR adding that information to the docs (there are 4-5 places where this can be added)?\n", "before_files": [{"content": "import logging\nimport platform\nimport ssl\nimport sys\nimport typing\n\nimport click\n\nimport uvicorn\nfrom uvicorn.config import (\n    HTTP_PROTOCOLS,\n    INTERFACES,\n    LIFESPAN,\n    LOG_LEVELS,\n    LOGGING_CONFIG,\n    LOOP_SETUPS,\n    SSL_PROTOCOL_VERSION,\n    WS_PROTOCOLS,\n    Config,\n)\nfrom uvicorn.server import Server, ServerState  # noqa: F401  # Used to be defined here.\nfrom uvicorn.supervisors import ChangeReload, Multiprocess\n\nLEVEL_CHOICES = click.Choice(LOG_LEVELS.keys())\nHTTP_CHOICES = click.Choice(HTTP_PROTOCOLS.keys())\nWS_CHOICES = click.Choice(WS_PROTOCOLS.keys())\nLIFESPAN_CHOICES = click.Choice(LIFESPAN.keys())\nLOOP_CHOICES = click.Choice([key for key in LOOP_SETUPS.keys() if key != \"none\"])\nINTERFACE_CHOICES = click.Choice(INTERFACES)\n\nlogger = logging.getLogger(\"uvicorn.error\")\n\n\ndef print_version(ctx, param, value):\n    if not value or ctx.resilient_parsing:\n        return\n    click.echo(\n        \"Running uvicorn %s with %s %s on %s\"\n        % (\n            uvicorn.__version__,\n            platform.python_implementation(),\n            platform.python_version(),\n            platform.system(),\n        )\n    )\n    ctx.exit()\n\n\n@click.command()\n@click.argument(\"app\")\n@click.option(\n    \"--host\",\n    type=str,\n    default=\"127.0.0.1\",\n    help=\"Bind socket to this host.\",\n    show_default=True,\n)\n@click.option(\n    \"--port\",\n    type=int,\n    default=8000,\n    help=\"Bind socket to this port.\",\n    show_default=True,\n)\n@click.option(\"--uds\", type=str, default=None, help=\"Bind to a UNIX domain socket.\")\n@click.option(\n    \"--fd\", type=int, default=None, help=\"Bind to socket from this file descriptor.\"\n)\n@click.option(\n    \"--debug\", is_flag=True, default=False, help=\"Enable debug mode.\", hidden=True\n)\n@click.option(\"--reload\", is_flag=True, default=False, help=\"Enable auto-reload.\")\n@click.option(\n    \"--reload-dir\",\n    \"reload_dirs\",\n    multiple=True,\n    help=\"Set reload directories explicitly, instead of using the current working\"\n    \" directory.\",\n)\n@click.option(\n    \"--reload-delay\",\n    type=float,\n    default=0.25,\n    show_default=True,\n    help=\"Delay between previous and next check if application needs to be.\"\n    \" Defaults to 0.25s.\",\n)\n@click.option(\n    \"--workers\",\n    default=None,\n    type=int,\n    help=\"Number of worker processes. Defaults to the $WEB_CONCURRENCY environment\"\n    \" variable if available. Not valid with --reload.\",\n)\n@click.option(\n    \"--loop\",\n    type=LOOP_CHOICES,\n    default=\"auto\",\n    help=\"Event loop implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--http\",\n    type=HTTP_CHOICES,\n    default=\"auto\",\n    help=\"HTTP protocol implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--ws\",\n    type=WS_CHOICES,\n    default=\"auto\",\n    help=\"WebSocket protocol implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--lifespan\",\n    type=LIFESPAN_CHOICES,\n    default=\"auto\",\n    help=\"Lifespan implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--interface\",\n    type=INTERFACE_CHOICES,\n    default=\"auto\",\n    help=\"Select ASGI3, ASGI2, or WSGI as the application interface.\",\n    show_default=True,\n)\n@click.option(\n    \"--env-file\",\n    type=click.Path(exists=True),\n    default=None,\n    help=\"Environment configuration file.\",\n    show_default=True,\n)\n@click.option(\n    \"--log-config\",\n    type=click.Path(exists=True),\n    default=None,\n    help=\"Logging configuration file. Supported formats: .ini, .json, .yaml.\",\n    show_default=True,\n)\n@click.option(\n    \"--log-level\",\n    type=LEVEL_CHOICES,\n    default=None,\n    help=\"Log level. [default: info]\",\n    show_default=True,\n)\n@click.option(\n    \"--access-log/--no-access-log\",\n    is_flag=True,\n    default=True,\n    help=\"Enable/Disable access log.\",\n)\n@click.option(\n    \"--use-colors/--no-use-colors\",\n    is_flag=True,\n    default=None,\n    help=\"Enable/Disable colorized logging.\",\n)\n@click.option(\n    \"--proxy-headers/--no-proxy-headers\",\n    is_flag=True,\n    default=True,\n    help=\"Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to \"\n    \"populate remote address info.\",\n)\n@click.option(\n    \"--forwarded-allow-ips\",\n    type=str,\n    default=None,\n    help=\"Comma seperated list of IPs to trust with proxy headers. Defaults to\"\n    \" the $FORWARDED_ALLOW_IPS environment variable if available, or '127.0.0.1'.\",\n)\n@click.option(\n    \"--root-path\",\n    type=str,\n    default=\"\",\n    help=\"Set the ASGI 'root_path' for applications submounted below a given URL path.\",\n)\n@click.option(\n    \"--limit-concurrency\",\n    type=int,\n    default=None,\n    help=\"Maximum number of concurrent connections or tasks to allow, before issuing\"\n    \" HTTP 503 responses.\",\n)\n@click.option(\n    \"--backlog\",\n    type=int,\n    default=2048,\n    help=\"Maximum number of connections to hold in backlog\",\n)\n@click.option(\n    \"--limit-max-requests\",\n    type=int,\n    default=None,\n    help=\"Maximum number of requests to service before terminating the process.\",\n)\n@click.option(\n    \"--timeout-keep-alive\",\n    type=int,\n    default=5,\n    help=\"Close Keep-Alive connections if no new data is received within this timeout.\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-keyfile\", type=str, default=None, help=\"SSL key file\", show_default=True\n)\n@click.option(\n    \"--ssl-certfile\",\n    type=str,\n    default=None,\n    help=\"SSL certificate file\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-keyfile-password\",\n    type=str,\n    default=None,\n    help=\"SSL keyfile password\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-version\",\n    type=int,\n    default=SSL_PROTOCOL_VERSION,\n    help=\"SSL version to use (see stdlib ssl module's)\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-cert-reqs\",\n    type=int,\n    default=ssl.CERT_NONE,\n    help=\"Whether client certificate is required (see stdlib ssl module's)\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-ca-certs\",\n    type=str,\n    default=None,\n    help=\"CA certificates file\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-ciphers\",\n    type=str,\n    default=\"TLSv1\",\n    help=\"Ciphers to use (see stdlib ssl module's)\",\n    show_default=True,\n)\n@click.option(\n    \"--header\",\n    \"headers\",\n    multiple=True,\n    help=\"Specify custom default HTTP response headers as a Name:Value pair\",\n)\n@click.option(\n    \"--version\",\n    is_flag=True,\n    callback=print_version,\n    expose_value=False,\n    is_eager=True,\n    help=\"Display the uvicorn version and exit.\",\n)\n@click.option(\n    \"--app-dir\",\n    \"app_dir\",\n    default=\".\",\n    show_default=True,\n    help=\"Look for APP in the specified directory, by adding this to the PYTHONPATH.\"\n    \" Defaults to the current working directory.\",\n)\n@click.option(\n    \"--factory\",\n    is_flag=True,\n    default=False,\n    help=\"Treat APP as an application factory, i.e. a () -> <ASGI app> callable.\",\n    show_default=True,\n)\ndef main(\n    app,\n    host: str,\n    port: int,\n    uds: str,\n    fd: int,\n    loop: str,\n    http: str,\n    ws: str,\n    lifespan: str,\n    interface: str,\n    debug: bool,\n    reload: bool,\n    reload_dirs: typing.List[str],\n    reload_delay: float,\n    workers: int,\n    env_file: str,\n    log_config: str,\n    log_level: str,\n    access_log: bool,\n    proxy_headers: bool,\n    forwarded_allow_ips: str,\n    root_path: str,\n    limit_concurrency: int,\n    backlog: int,\n    limit_max_requests: int,\n    timeout_keep_alive: int,\n    ssl_keyfile: str,\n    ssl_certfile: str,\n    ssl_keyfile_password: str,\n    ssl_version: int,\n    ssl_cert_reqs: int,\n    ssl_ca_certs: str,\n    ssl_ciphers: str,\n    headers: typing.List[str],\n    use_colors: bool,\n    app_dir: str,\n    factory: bool,\n):\n    sys.path.insert(0, app_dir)\n\n    kwargs = {\n        \"app\": app,\n        \"host\": host,\n        \"port\": port,\n        \"uds\": uds,\n        \"fd\": fd,\n        \"loop\": loop,\n        \"http\": http,\n        \"ws\": ws,\n        \"lifespan\": lifespan,\n        \"env_file\": env_file,\n        \"log_config\": LOGGING_CONFIG if log_config is None else log_config,\n        \"log_level\": log_level,\n        \"access_log\": access_log,\n        \"interface\": interface,\n        \"debug\": debug,\n        \"reload\": reload,\n        \"reload_dirs\": reload_dirs if reload_dirs else None,\n        \"reload_delay\": reload_delay,\n        \"workers\": workers,\n        \"proxy_headers\": proxy_headers,\n        \"forwarded_allow_ips\": forwarded_allow_ips,\n        \"root_path\": root_path,\n        \"limit_concurrency\": limit_concurrency,\n        \"backlog\": backlog,\n        \"limit_max_requests\": limit_max_requests,\n        \"timeout_keep_alive\": timeout_keep_alive,\n        \"ssl_keyfile\": ssl_keyfile,\n        \"ssl_certfile\": ssl_certfile,\n        \"ssl_keyfile_password\": ssl_keyfile_password,\n        \"ssl_version\": ssl_version,\n        \"ssl_cert_reqs\": ssl_cert_reqs,\n        \"ssl_ca_certs\": ssl_ca_certs,\n        \"ssl_ciphers\": ssl_ciphers,\n        \"headers\": [header.split(\":\", 1) for header in headers],\n        \"use_colors\": use_colors,\n        \"factory\": factory,\n    }\n    run(**kwargs)\n\n\ndef run(app, **kwargs):\n    config = Config(app, **kwargs)\n    server = Server(config=config)\n\n    if (config.reload or config.workers > 1) and not isinstance(app, str):\n        logger = logging.getLogger(\"uvicorn.error\")\n        logger.warning(\n            \"You must pass the application as an import string to enable 'reload' or \"\n            \"'workers'.\"\n        )\n        sys.exit(1)\n\n    if config.should_reload:\n        sock = config.bind_socket()\n        supervisor = ChangeReload(config, target=server.run, sockets=[sock])\n        supervisor.run()\n    elif config.workers > 1:\n        sock = config.bind_socket()\n        supervisor = Multiprocess(config, target=server.run, sockets=[sock])\n        supervisor.run()\n    else:\n        server.run()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "uvicorn/main.py"}], "after_files": [{"content": "import logging\nimport platform\nimport ssl\nimport sys\nimport typing\n\nimport click\n\nimport uvicorn\nfrom uvicorn.config import (\n    HTTP_PROTOCOLS,\n    INTERFACES,\n    LIFESPAN,\n    LOG_LEVELS,\n    LOGGING_CONFIG,\n    LOOP_SETUPS,\n    SSL_PROTOCOL_VERSION,\n    WS_PROTOCOLS,\n    Config,\n)\nfrom uvicorn.server import Server, ServerState  # noqa: F401  # Used to be defined here.\nfrom uvicorn.supervisors import ChangeReload, Multiprocess\n\nLEVEL_CHOICES = click.Choice(LOG_LEVELS.keys())\nHTTP_CHOICES = click.Choice(HTTP_PROTOCOLS.keys())\nWS_CHOICES = click.Choice(WS_PROTOCOLS.keys())\nLIFESPAN_CHOICES = click.Choice(LIFESPAN.keys())\nLOOP_CHOICES = click.Choice([key for key in LOOP_SETUPS.keys() if key != \"none\"])\nINTERFACE_CHOICES = click.Choice(INTERFACES)\n\nlogger = logging.getLogger(\"uvicorn.error\")\n\n\ndef print_version(ctx, param, value):\n    if not value or ctx.resilient_parsing:\n        return\n    click.echo(\n        \"Running uvicorn %s with %s %s on %s\"\n        % (\n            uvicorn.__version__,\n            platform.python_implementation(),\n            platform.python_version(),\n            platform.system(),\n        )\n    )\n    ctx.exit()\n\n\n@click.command()\n@click.argument(\"app\")\n@click.option(\n    \"--host\",\n    type=str,\n    default=\"127.0.0.1\",\n    help=\"Bind socket to this host.\",\n    show_default=True,\n)\n@click.option(\n    \"--port\",\n    type=int,\n    default=8000,\n    help=\"Bind socket to this port.\",\n    show_default=True,\n)\n@click.option(\"--uds\", type=str, default=None, help=\"Bind to a UNIX domain socket.\")\n@click.option(\n    \"--fd\", type=int, default=None, help=\"Bind to socket from this file descriptor.\"\n)\n@click.option(\n    \"--debug\", is_flag=True, default=False, help=\"Enable debug mode.\", hidden=True\n)\n@click.option(\"--reload\", is_flag=True, default=False, help=\"Enable auto-reload.\")\n@click.option(\n    \"--reload-dir\",\n    \"reload_dirs\",\n    multiple=True,\n    help=\"Set reload directories explicitly, instead of using the current working\"\n    \" directory.\",\n)\n@click.option(\n    \"--reload-delay\",\n    type=float,\n    default=0.25,\n    show_default=True,\n    help=\"Delay between previous and next check if application needs to be.\"\n    \" Defaults to 0.25s.\",\n)\n@click.option(\n    \"--workers\",\n    default=None,\n    type=int,\n    help=\"Number of worker processes. Defaults to the $WEB_CONCURRENCY environment\"\n    \" variable if available, or 1. Not valid with --reload.\",\n)\n@click.option(\n    \"--loop\",\n    type=LOOP_CHOICES,\n    default=\"auto\",\n    help=\"Event loop implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--http\",\n    type=HTTP_CHOICES,\n    default=\"auto\",\n    help=\"HTTP protocol implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--ws\",\n    type=WS_CHOICES,\n    default=\"auto\",\n    help=\"WebSocket protocol implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--lifespan\",\n    type=LIFESPAN_CHOICES,\n    default=\"auto\",\n    help=\"Lifespan implementation.\",\n    show_default=True,\n)\n@click.option(\n    \"--interface\",\n    type=INTERFACE_CHOICES,\n    default=\"auto\",\n    help=\"Select ASGI3, ASGI2, or WSGI as the application interface.\",\n    show_default=True,\n)\n@click.option(\n    \"--env-file\",\n    type=click.Path(exists=True),\n    default=None,\n    help=\"Environment configuration file.\",\n    show_default=True,\n)\n@click.option(\n    \"--log-config\",\n    type=click.Path(exists=True),\n    default=None,\n    help=\"Logging configuration file. Supported formats: .ini, .json, .yaml.\",\n    show_default=True,\n)\n@click.option(\n    \"--log-level\",\n    type=LEVEL_CHOICES,\n    default=None,\n    help=\"Log level. [default: info]\",\n    show_default=True,\n)\n@click.option(\n    \"--access-log/--no-access-log\",\n    is_flag=True,\n    default=True,\n    help=\"Enable/Disable access log.\",\n)\n@click.option(\n    \"--use-colors/--no-use-colors\",\n    is_flag=True,\n    default=None,\n    help=\"Enable/Disable colorized logging.\",\n)\n@click.option(\n    \"--proxy-headers/--no-proxy-headers\",\n    is_flag=True,\n    default=True,\n    help=\"Enable/Disable X-Forwarded-Proto, X-Forwarded-For, X-Forwarded-Port to \"\n    \"populate remote address info.\",\n)\n@click.option(\n    \"--forwarded-allow-ips\",\n    type=str,\n    default=None,\n    help=\"Comma seperated list of IPs to trust with proxy headers. Defaults to\"\n    \" the $FORWARDED_ALLOW_IPS environment variable if available, or '127.0.0.1'.\",\n)\n@click.option(\n    \"--root-path\",\n    type=str,\n    default=\"\",\n    help=\"Set the ASGI 'root_path' for applications submounted below a given URL path.\",\n)\n@click.option(\n    \"--limit-concurrency\",\n    type=int,\n    default=None,\n    help=\"Maximum number of concurrent connections or tasks to allow, before issuing\"\n    \" HTTP 503 responses.\",\n)\n@click.option(\n    \"--backlog\",\n    type=int,\n    default=2048,\n    help=\"Maximum number of connections to hold in backlog\",\n)\n@click.option(\n    \"--limit-max-requests\",\n    type=int,\n    default=None,\n    help=\"Maximum number of requests to service before terminating the process.\",\n)\n@click.option(\n    \"--timeout-keep-alive\",\n    type=int,\n    default=5,\n    help=\"Close Keep-Alive connections if no new data is received within this timeout.\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-keyfile\", type=str, default=None, help=\"SSL key file\", show_default=True\n)\n@click.option(\n    \"--ssl-certfile\",\n    type=str,\n    default=None,\n    help=\"SSL certificate file\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-keyfile-password\",\n    type=str,\n    default=None,\n    help=\"SSL keyfile password\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-version\",\n    type=int,\n    default=SSL_PROTOCOL_VERSION,\n    help=\"SSL version to use (see stdlib ssl module's)\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-cert-reqs\",\n    type=int,\n    default=ssl.CERT_NONE,\n    help=\"Whether client certificate is required (see stdlib ssl module's)\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-ca-certs\",\n    type=str,\n    default=None,\n    help=\"CA certificates file\",\n    show_default=True,\n)\n@click.option(\n    \"--ssl-ciphers\",\n    type=str,\n    default=\"TLSv1\",\n    help=\"Ciphers to use (see stdlib ssl module's)\",\n    show_default=True,\n)\n@click.option(\n    \"--header\",\n    \"headers\",\n    multiple=True,\n    help=\"Specify custom default HTTP response headers as a Name:Value pair\",\n)\n@click.option(\n    \"--version\",\n    is_flag=True,\n    callback=print_version,\n    expose_value=False,\n    is_eager=True,\n    help=\"Display the uvicorn version and exit.\",\n)\n@click.option(\n    \"--app-dir\",\n    \"app_dir\",\n    default=\".\",\n    show_default=True,\n    help=\"Look for APP in the specified directory, by adding this to the PYTHONPATH.\"\n    \" Defaults to the current working directory.\",\n)\n@click.option(\n    \"--factory\",\n    is_flag=True,\n    default=False,\n    help=\"Treat APP as an application factory, i.e. a () -> <ASGI app> callable.\",\n    show_default=True,\n)\ndef main(\n    app,\n    host: str,\n    port: int,\n    uds: str,\n    fd: int,\n    loop: str,\n    http: str,\n    ws: str,\n    lifespan: str,\n    interface: str,\n    debug: bool,\n    reload: bool,\n    reload_dirs: typing.List[str],\n    reload_delay: float,\n    workers: int,\n    env_file: str,\n    log_config: str,\n    log_level: str,\n    access_log: bool,\n    proxy_headers: bool,\n    forwarded_allow_ips: str,\n    root_path: str,\n    limit_concurrency: int,\n    backlog: int,\n    limit_max_requests: int,\n    timeout_keep_alive: int,\n    ssl_keyfile: str,\n    ssl_certfile: str,\n    ssl_keyfile_password: str,\n    ssl_version: int,\n    ssl_cert_reqs: int,\n    ssl_ca_certs: str,\n    ssl_ciphers: str,\n    headers: typing.List[str],\n    use_colors: bool,\n    app_dir: str,\n    factory: bool,\n):\n    sys.path.insert(0, app_dir)\n\n    kwargs = {\n        \"app\": app,\n        \"host\": host,\n        \"port\": port,\n        \"uds\": uds,\n        \"fd\": fd,\n        \"loop\": loop,\n        \"http\": http,\n        \"ws\": ws,\n        \"lifespan\": lifespan,\n        \"env_file\": env_file,\n        \"log_config\": LOGGING_CONFIG if log_config is None else log_config,\n        \"log_level\": log_level,\n        \"access_log\": access_log,\n        \"interface\": interface,\n        \"debug\": debug,\n        \"reload\": reload,\n        \"reload_dirs\": reload_dirs if reload_dirs else None,\n        \"reload_delay\": reload_delay,\n        \"workers\": workers,\n        \"proxy_headers\": proxy_headers,\n        \"forwarded_allow_ips\": forwarded_allow_ips,\n        \"root_path\": root_path,\n        \"limit_concurrency\": limit_concurrency,\n        \"backlog\": backlog,\n        \"limit_max_requests\": limit_max_requests,\n        \"timeout_keep_alive\": timeout_keep_alive,\n        \"ssl_keyfile\": ssl_keyfile,\n        \"ssl_certfile\": ssl_certfile,\n        \"ssl_keyfile_password\": ssl_keyfile_password,\n        \"ssl_version\": ssl_version,\n        \"ssl_cert_reqs\": ssl_cert_reqs,\n        \"ssl_ca_certs\": ssl_ca_certs,\n        \"ssl_ciphers\": ssl_ciphers,\n        \"headers\": [header.split(\":\", 1) for header in headers],\n        \"use_colors\": use_colors,\n        \"factory\": factory,\n    }\n    run(**kwargs)\n\n\ndef run(app, **kwargs):\n    config = Config(app, **kwargs)\n    server = Server(config=config)\n\n    if (config.reload or config.workers > 1) and not isinstance(app, str):\n        logger = logging.getLogger(\"uvicorn.error\")\n        logger.warning(\n            \"You must pass the application as an import string to enable 'reload' or \"\n            \"'workers'.\"\n        )\n        sys.exit(1)\n\n    if config.should_reload:\n        sock = config.bind_socket()\n        supervisor = ChangeReload(config, target=server.run, sockets=[sock])\n        supervisor.run()\n    elif config.workers > 1:\n        sock = config.bind_socket()\n        supervisor = Multiprocess(config, target=server.run, sockets=[sock])\n        supervisor.run()\n    else:\n        server.run()\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "uvicorn/main.py"}]}