https://github.com/python/cpython/commit/e272195b3eff3a78e334a601a637d198b8de2319
commit: e272195b3eff3a78e334a601a637d198b8de2319
branch: main
author: Dino Viehland <[email protected]>
committer: DinoV <[email protected]>
date: 2024-05-06T16:45:04-07:00
summary:

gh-118362: Skip tests when threading isn't available (#118666)

* Skip tests when threads aren't available

* Use ThreadPoolExecutor

files:
M Lib/test/test_free_threading/test_list.py
M Lib/test/test_free_threading/test_monitoring.py
M Lib/test/test_free_threading/test_type.py

diff --git a/Lib/test/test_free_threading/test_list.py 
b/Lib/test/test_free_threading/test_list.py
index 79cb0a93092365..6ad806d67a80ed 100644
--- a/Lib/test/test_free_threading/test_list.py
+++ b/Lib/test/test_free_threading/test_list.py
@@ -3,7 +3,7 @@
 from threading import Thread
 from unittest import TestCase
 
-from test.support import is_wasi
+from test.support import threading_helper
 
 
 class C:
@@ -11,7 +11,7 @@ def __init__(self, v):
         self.v = v
 
 
[email protected](is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class TestList(TestCase):
     def test_racing_iter_append(self):
 
diff --git a/Lib/test/test_free_threading/test_monitoring.py 
b/Lib/test/test_free_threading/test_monitoring.py
index fa588046bf9923..3a3f1ba3b605d6 100644
--- a/Lib/test/test_free_threading/test_monitoring.py
+++ b/Lib/test/test_free_threading/test_monitoring.py
@@ -7,7 +7,7 @@
 import weakref
 
 from sys import monitoring
-from test.support import is_wasi
+from test.support import threading_helper
 from threading import Thread, _PyRLock
 from unittest import TestCase
 
@@ -87,7 +87,7 @@ def tearDown(self):
         monitoring.free_tool_id(self.tool_id)
 
 
[email protected](is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class SetPreTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
     """Sets tracing one time after the threads have started"""
 
@@ -106,7 +106,7 @@ def after_threads(self):
         sys.settrace(self.trace_func)
 
 
[email protected](is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class MonitoringMultiThreaded(
     MonitoringTestMixin, InstrumentationMultiThreadedMixin, TestCase
 ):
@@ -140,7 +140,7 @@ def during_threads(self):
         self.set = not self.set
 
 
[email protected](is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class SetTraceMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
     """Uses sys.settrace and repeatedly toggles instrumentation on and off"""
 
@@ -166,7 +166,7 @@ def during_threads(self):
         self.set = not self.set
 
 
[email protected](is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class SetProfileMultiThreaded(InstrumentationMultiThreadedMixin, TestCase):
     """Uses sys.setprofile and repeatedly toggles instrumentation on and off"""
 
@@ -192,7 +192,7 @@ def during_threads(self):
         self.set = not self.set
 
 
[email protected](is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class MonitoringMisc(MonitoringTestMixin, TestCase):
     def register_callback(self):
         def callback(*args):
diff --git a/Lib/test/test_free_threading/test_type.py 
b/Lib/test/test_free_threading/test_type.py
index 76208c42fc8aea..6eead198deed46 100644
--- a/Lib/test/test_free_threading/test_type.py
+++ b/Lib/test/test_free_threading/test_type.py
@@ -1,10 +1,11 @@
 import unittest
 
+from concurrent.futures import ThreadPoolExecutor
 from threading import Thread
-from multiprocessing.dummy import Pool
 from unittest import TestCase
 
-from test.support import is_wasi
+from test.support import threading_helper, import_helper
+
 
 
 NTHREADS = 6
@@ -15,7 +16,7 @@
 class A:
     attr = 1
 
[email protected](is_wasi, "WASI has no threads.")
+@threading_helper.requires_working_threading()
 class TestType(TestCase):
     def test_attr_cache(self):
         def read(id0):
@@ -34,11 +35,10 @@ def write(id0):
                     A.attr = x
 
 
-        with Pool(NTHREADS) as pool:
-            pool.apply_async(read, (1,))
-            pool.apply_async(write, (1,))
-            pool.close()
-            pool.join()
+        with ThreadPoolExecutor(NTHREADS) as pool:
+            pool.submit(read, (1,))
+            pool.submit(write, (1,))
+            pool.shutdown(wait=True)
 
     def test_attr_cache_consistency(self):
         class C:

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to