diff options
author | Christian Heimes <christian@python.org> | 2022-04-02 08:12:44 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-02 08:12:44 (GMT) |
commit | 59be9cd748728b03ac61287681c3010bcec5e558 (patch) | |
tree | 4c2f258108f56732974bc5675d4fd9e35ca7bff2 | |
parent | 7000cd70164707e28ba045b5c036ca7ed73f5dc4 (diff) | |
download | cpython-59be9cd748728b03ac61287681c3010bcec5e558.zip cpython-59be9cd748728b03ac61287681c3010bcec5e558.tar.gz cpython-59be9cd748728b03ac61287681c3010bcec5e558.tar.bz2 |
bpo-40280: Detect if WASM platform supports threading (GH-32243)
Automerge-Triggered-By: GH:tiran
-rw-r--r-- | Lib/test/libregrtest/runtest.py | 5 | ||||
-rw-r--r-- | Lib/test/support/threading_helper.py | 27 |
2 files changed, 31 insertions, 1 deletions
diff --git a/Lib/test/libregrtest/runtest.py b/Lib/test/libregrtest/runtest.py index 83c5f24..62cf1a3 100644 --- a/Lib/test/libregrtest/runtest.py +++ b/Lib/test/libregrtest/runtest.py @@ -11,6 +11,7 @@ import unittest from test import support from test.support import os_helper +from test.support import threading_helper from test.libregrtest.cmdline import Namespace from test.libregrtest.save_env import saved_test_environment from test.libregrtest.utils import clear_caches, format_duration, print_warning @@ -179,7 +180,9 @@ def _runtest(ns: Namespace, test_name: str) -> TestResult: output_on_failure = ns.verbose3 - use_timeout = (ns.timeout is not None) + use_timeout = ( + ns.timeout is not None and threading_helper.can_start_thread + ) if use_timeout: faulthandler.dump_traceback_later(ns.timeout, exit=True) diff --git a/Lib/test/support/threading_helper.py b/Lib/test/support/threading_helper.py index 92a64e8..2ae4577 100644 --- a/Lib/test/support/threading_helper.py +++ b/Lib/test/support/threading_helper.py @@ -207,3 +207,30 @@ class catch_threading_exception: del self.exc_value del self.exc_traceback del self.thread + + +def _can_start_thread() -> bool: + """Detect if Python can start new threads. + + Some WebAssembly platforms do not provide a working pthread + implementation. Thread support is stubbed and any attempt + to create a new thread fails. + + - wasm32-wasi does not have threading. + - wasm32-emscripten can be compiled with or without pthread + support (-s USE_PTHREADS / __EMSCRIPTEN_PTHREADS__). + """ + if sys.platform == "emscripten": + try: + _thread.start_new_thread(lambda: None, ()) + except RuntimeError: + return False + else: + return True + elif sys.platform == "wasi": + return False + else: + # assume all other platforms have working thread support. + return True + +can_start_thread = _can_start_thread() |