Called in the parent process, to instantiate a new child process instance. The child is not yet started at this point. * config - The Uvicorn configuration instance. * target - A callable that accepts a list of sockets. In practice this will be the `Server.run()` met
(
config: Config,
target: Callable[..., None],
sockets: list[socket],
)
| 19 | |
| 20 | |
| 21 | def get_subprocess( |
| 22 | config: Config, |
| 23 | target: Callable[..., None], |
| 24 | sockets: list[socket], |
| 25 | ) -> SpawnProcess: |
| 26 | """ |
| 27 | Called in the parent process, to instantiate a new child process instance. |
| 28 | The child is not yet started at this point. |
| 29 | |
| 30 | * config - The Uvicorn configuration instance. |
| 31 | * target - A callable that accepts a list of sockets. In practice this will |
| 32 | be the `Server.run()` method. |
| 33 | * sockets - A list of sockets to pass to the server. Sockets are bound once |
| 34 | by the parent process, and then passed to the child processes. |
| 35 | """ |
| 36 | # We pass across the stdin fileno, and reopen it in the child process. |
| 37 | # This is required for some debugging environments. |
| 38 | try: |
| 39 | stdin_fileno = sys.stdin.fileno() |
| 40 | # The `sys.stdin` can be `None`, see https://docs.python.org/3/library/sys.html#sys.__stdin__. |
| 41 | except (AttributeError, OSError): |
| 42 | stdin_fileno = None |
| 43 | |
| 44 | kwargs = { |
| 45 | "config": config, |
| 46 | "target": target, |
| 47 | "sockets": sockets, |
| 48 | "stdin_fileno": stdin_fileno, |
| 49 | } |
| 50 | |
| 51 | return spawn.Process(target=subprocess_started, kwargs=kwargs) |
| 52 | |
| 53 | |
| 54 | def subprocess_started( |
no outgoing calls