1+ import argparse
12import json
23import os
34import pathlib
45import sys
56from typing import cast
67
8+
79import uvicorn
810from uvicorn .supervisors import Multiprocess
911
@@ -24,20 +26,19 @@ def get_config() -> dict[str, dict[str, int | str]]:
2426
2527 return data
2628
27-
28- async def run_cli ():
29- pass
30-
31-
32- def run_cli_with_workers ():
33- pass
34-
35-
3629if __name__ == "__main__" :
3730 cfg = get_config ()
3831 port = cast (int , cfg ["site" ]["backend_port" ])
39- use_workers = "--no-workers" not in sys .argv and cfg ["redis" ]["use-redis" ]
40- use_cli = "--no-cli" not in sys .argv
32+ parser = argparse .ArgumentParser (prog = "Mystbin" )
33+ parser .add_argument ("--no-workers" , "-nw" , action = "store_true" , default = False )
34+ parser .add_argument ("--no-cli" , "-nc" , action = "store_true" , default = False )
35+ parser .add_argument ("--workers" , "-w" , nargs = 1 , default = os .cpu_count () or 1 )
36+
37+ ns = parser .parse_args (sys .argv [1 :])
38+
39+ use_workers : bool = not ns .no_workers
40+ use_cli : bool = not ns .no_cli
41+ worker_count : int = ns .workers
4142 _cli_path = pathlib .Path (".nocli" )
4243
4344 if not use_cli :
@@ -57,7 +58,7 @@ def run_cli_with_workers():
5758 server = uvicorn .Server (config )
5859
5960 if use_workers :
60- config .workers = os . cpu_count () or 1
61+ config .workers = worker_count
6162 sock = config .bind_socket ()
6263
6364 runner = Multiprocess (config , target = server .run , sockets = [sock ])
0 commit comments