pcs/SOURCES/Use-forkserver-process-creation-method-for-multiprocessing.patch
eabdullin 9dc9761287 - fix logging handlers imports
- Use 'forkserver' process creation method for multiprocessing
2024-07-24 12:20:47 +03:00

35 lines
1.2 KiB
Diff

From 2fc4a70cb977b646befa059b99ceabe368f27229 Mon Sep 17 00:00:00 2001
From: Miroslav Lisik <mlisik@redhat.com>
Date: Thu, 21 Mar 2024 13:32:10 +0100
Subject: [PATCH] Use 'forkserver' process creation method for multiprocessing
* 'fork' method could cause deadlock in multiprocessing.pool.Pool on
terminate (https://github.com/python/cpython/issues/73945)
* https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
---
pcs/daemon/run.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/pcs/daemon/run.py b/pcs/daemon/run.py
index 5fa083fd5..cecce750f 100644
--- a/pcs/daemon/run.py
+++ b/pcs/daemon/run.py
@@ -1,3 +1,4 @@
+import multiprocessing as mp
import os
import signal
import socket
@@ -157,6 +158,12 @@ def _print_version(argv: StringCollection) -> None:
def main(argv=None) -> None:
+ # set the way how processes are started
+ # https://docs.python.org/3/library/multiprocessing.html#contexts-and-start-methods
+ # avoid deadlock in multiprocessing.pool.Pool on terminate
+ # https://github.com/python/cpython/issues/73945
+ mp.set_start_method(method="forkserver")
+
argv = argv if argv is not None else sys.argv[1:]
if "--version" in argv:
_print_version(argv)