socketify.py/bench/socketify_plaintext.py

21 wiersze
557 B
Python
Czysty Zwykły widok Historia

2022-11-08 13:07:18 +00:00
from socketify import App
2022-11-10 11:39:25 +00:00
import os
import multiprocessing
def run_app():
app = App()
app.get("/", lambda res, req: res.end("Hello, World!"))
app.listen(8000, lambda config: print("PID %d Listening on port http://localhost:%d now\n" % (os.getpid(), 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()
2022-11-10 15:20:40 +00:00
run_app() # run app on the main process too :)