mirror of
https://github.com/outbackdingo/patroni.git
synced 2026-08-25 14:53:37 +00:00
Use "spawn" multiprocessing start method (#1279)
workaround https://bugs.python.org/issue6721 Fixes #1278
This commit is contained in:
committed by
Alexander Kukushkin
parent
66d77697ae
commit
efcd05ace2
@@ -176,6 +176,13 @@ def fatal(string, *args):
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def use_spawn_start_method():
|
||||
if sys.version_info >= (3, 4):
|
||||
# The default, forking, method is not a good idea in a multithreaded process: https://bugs.python.org/issue6721
|
||||
import multiprocessing
|
||||
multiprocessing.set_start_method('spawn')
|
||||
|
||||
|
||||
def check_psycopg2():
|
||||
min_psycopg2 = (2, 5, 4)
|
||||
min_psycopg2_str = '.'.join(map(str, min_psycopg2))
|
||||
@@ -198,6 +205,7 @@ def check_psycopg2():
|
||||
|
||||
|
||||
def main():
|
||||
use_spawn_start_method()
|
||||
check_psycopg2()
|
||||
if os.getpid() != 1:
|
||||
return patroni_main()
|
||||
|
||||
@@ -83,6 +83,7 @@ class TestPatroni(unittest.TestCase):
|
||||
|
||||
@patch('os.getpid')
|
||||
@patch('multiprocessing.Process')
|
||||
@patch('patroni.use_spawn_start_method', Mock())
|
||||
@patch('patroni.patroni_main', Mock())
|
||||
def test_patroni_main(self, mock_process, mock_getpid):
|
||||
mock_getpid.return_value = 2
|
||||
|
||||
Reference in New Issue
Block a user