From b8addc7ad9990d1ba3786830ebd74aa8c939849d Mon Sep 17 00:00:00 2001 From: Allan Que Date: Sun, 3 Oct 2021 20:16:40 -0500 Subject: test_bio_membuf: Use fork when running on MacOS Restores Python pre-3.8 multiprocessing start method when running test_readline() under MacOS. Fixes #286 --- tests/test_bio_membuf.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/tests/test_bio_membuf.py b/tests/test_bio_membuf.py index 16e9c03..6fe5120 100644 --- a/tests/test_bio_membuf.py +++ b/tests/test_bio_membuf.py @@ -7,6 +7,9 @@ Copyright (c) 2000 Ng Pheng Siong. All rights reserved.""" import os import multiprocessing +from platform import system +from sys import version_info +from M2Crypto import six from M2Crypto.BIO import MemoryBuffer from tests import unittest @@ -16,7 +19,23 @@ class TimeLimitExpired(Exception): def time_limit(timeout, func, exc_msg, *args, **kwargs): - p = multiprocessing.Process(target=func) + + # multiprocessing.get_context() available in Python >= 3.4 + if six.PY3: + # Python >=3.8 on MacOS changed start_method to 'spawn' as default. + # This creates a new context with the previous 'fork' + # start_method. Fixes issue #286. + if system() == 'Darwin' and version_info.major >= 3 and version_info.minor >= 8: + start_method = 'fork' + else: + # use default context + start_method = None + + mp = multiprocessing.get_context(start_method) + else: + mp = multiprocessing + + p = mp.Process(target=func) p.start() p.join(timeout) if p.is_alive(): -- cgit v1.2.1