socketify.py/tests/examples/forks.py

21 wiersze
556 B
Python
Czysty Zwykły widok Historia

2022-05-31 21:51:39 +00:00
from socketify import App
import os
import multiprocessing
def run_app():
app = App()
app.get("/", lambda res, req: res.end("Hello World socketify from Python!"))
app.listen(3000, lambda config: print("Listening on port http://localhost:%d now\n" % config.port))
app.run()
def create_fork():
n = os.fork()
# n greater than 0 means parent process
if not n > 0:
run_app()
# fork limiting the cpu count - 1
for i in range(1, multiprocessing.cpu_count()):
create_fork()
run_app() # run app on the main process too :)