pull/75/head
Ciro 2023-03-12 16:08:54 -03:00
rodzic 620b853607
commit 23f6e26d26
4 zmienionych plików z 48 dodań i 37 usunięć

Wyświetl plik

@ -2,7 +2,6 @@ from socketify import App
import os
import multiprocessing
def run_app():
app = App()
app.get("/", lambda res, req: res.end("Hello, World!"))
@ -16,15 +15,19 @@ def run_app():
app.run()
def create_fork():
n = os.fork()
# n greater than 0 means parent process
if not n > 0:
run_app()
pid_list = []
# fork limiting the cpu count - 1
for i in range(1, multiprocessing.cpu_count()):
create_fork()
for _ in range(1, multiprocessing.cpu_count()):
pid = os.fork()
# n greater than 0 means parent process
if not pid > 0:
run_app()
break
pid_list.append(pid)
run_app() # run app on the main process too :)
# sigint everything to gracefull shutdown
import signal
for pid in pid_list:
os.kill(pid, signal.SIGINT)

Wyświetl plik

@ -771,15 +771,20 @@ class ASGI:
server.listen(port_or_options, handler)
server.run()
def create_fork():
n = os.fork()
# n greater than 0 means parent process
if not n > 0:
run_task()
pid_list = []
# fork limiting the cpu count - 1
for _ in range(1, workers):
create_fork()
pid = os.fork()
# n greater than 0 means parent process
if not pid > 0:
run_task()
break
pid_list.append(pid)
run_task() # run app on the main process too :)
# sigint everything to gracefull shutdown
import signal
for pid in pid_list:
os.kill(pid, signal.SIGINT)
return self

Wyświetl plik

@ -310,22 +310,20 @@ def execute(args):
fork_app.listen(AppListenOptions(port=port, host=host), listen_log)
fork_app.run()
# now we can start all over again
def create_fork(_):
n = os.fork()
pid_list = []
# fork limiting the cpu count - 1
for _ in range(1, workers):
pid = os.fork()
# n greater than 0 means parent process
if not n > 0:
if not pid > 0:
run_app()
return n
break
pid_list.append(pid)
# run in all forks
pid_list = list(map(create_fork, range(1, workers)))
run_app() # run app on the main process too :)
# run in this process
run_app()
# sigint everything to gracefull shutdown
import signal
for pid in pid_list:
os.kill(pid, signal.SIGINT)
else:

Wyświetl plik

@ -500,7 +500,7 @@ class WSGI:
return self
def run(self, workers=1):
def run_app():
def run_task():
server = _WSGI(
self.app,
self.options,
@ -513,15 +513,20 @@ class WSGI:
server.listen(port_or_options, handler)
server.run()
def create_fork():
n = os.fork()
# n greater than 0 means parent process
if not n > 0:
run_app()
pid_list = []
# fork limiting the cpu count - 1
for i in range(1, workers):
create_fork()
for _ in range(1, workers):
pid = os.fork()
# n greater than 0 means parent process
if not pid > 0:
run_task()
break
pid_list.append(pid)
run_app() # run app on the main process too :)
run_task() # run app on the main process too :)
# sigint everything to gracefull shutdown
import signal
for pid in pid_list:
os.kill(pid, signal.SIGINT)
return self