FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-40280: Detect if WASM platform supports threading by tiran · Pull Request #32243 · python/cpython · GitHub

/ cpython Public
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
5 changes: 4 additions & 1 deletion Lib/test/libregrtest/runtest.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

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
Expand Down Expand Up @@ -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)

Expand Down
27 changes: 27 additions & 0 deletions Lib/test/support/threading_helper.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,30 @@ def __exit__(self, *exc_info):
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()

Back | FazBrowse Home | New Git URL