From 489ba6bcf9e505ff2515089379a813cbc236b8f8 Mon Sep 17 00:00:00 2001 From: Sanskar Jethi Date: Tue, 23 Apr 2024 00:33:38 +0100 Subject: [PATCH] fix multiprocessing ml bug --- multtest.py | 12 ++++++++++++ robyn/processpool.py | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 multtest.py diff --git a/multtest.py b/multtest.py new file mode 100644 index 000000000..a385f1c3d --- /dev/null +++ b/multtest.py @@ -0,0 +1,12 @@ +import multiprocessing + +def worker(a): + print(a) + +if __name__ == '__main__': + a = [] + multiprocessing.set_start_method('spawn') + p = multiprocessing.Process(target=worker, args=('hello',)) + p.start() + a.append(p) + p.join() diff --git a/robyn/processpool.py b/robyn/processpool.py index 617304d35..f22a14302 100644 --- a/robyn/processpool.py +++ b/robyn/processpool.py @@ -1,7 +1,7 @@ import asyncio import webbrowser from multiprocess import Process -import multiprocessing as mp +import multiprocess as mp import signal import sys from typing import Dict, List @@ -78,7 +78,8 @@ def init_processpool( response_headers: Headers, ) -> List[Process]: process_pool = [] - ctx = mp.get_context('spawn') + ctx = mp.get_context('fork') + if sys.platform.startswith("win32"): spawn_process( @@ -98,7 +99,7 @@ def init_processpool( for _ in range(processes): copied_socket = socket.try_clone() - process = Process( + process = ctx.Process( target=spawn_process, args=( directories,