diff options
author | Allan Que <allan.que@gmail.com> | 2021-10-03 20:16:40 -0500 |
---|---|---|
committer | Allan Que <allan.que@gmail.com> | 2021-11-12 10:35:44 -0600 |
commit | b8addc7ad9990d1ba3786830ebd74aa8c939849d (patch) | |
tree | cabaa7932b886dcfc62329d16373cdae194ba142 | |
parent | 4a3a09af8165c446a731c50eeef0186c1f002cbf (diff) | |
download | m2crypto-b8addc7ad9990d1ba3786830ebd74aa8c939849d.tar.gz |
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
-rw-r--r-- | tests/test_bio_membuf.py | 21 |
1 files changed, 20 insertions, 1 deletions
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(): |