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

Fix @reap_threads usage in test_free_threading.test_json by vstinner · Pull Request #158937 · python/cpython · GitHub

Repository navigation

Open
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
6 changes: 6 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
@@ -1,6 +1,7 @@
import _thread
import contextlib
import functools
import inspect
import sys
import threading
import time
Expand Down Expand Up @@ -59,6 +60,11 @@ def reap_threads(func):
"""Use this function when threads are being used. This will
ensure that the threads are cleaned up even when the test fails.
"""

if inspect.isclass(func):
# It should be used on each test method, not on the whole class
raise ValueError("@reap_threads is not compatible with classes")

@functools.wraps(func)
def decorator(*args):
key = threading_setup()
Expand Down
4 changes: 3 additions & 1 deletion Lib/test/test_free_threading/test_json.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 @@ -29,12 +29,12 @@ def items(self):
return self.mapping


@threading_helper.reap_threads
@threading_helper.requires_working_threading()
class TestJsonEncoding(CTest):
# Test encoding json with concurrent threads modifying the data cannot
# corrupt the interpreter

@threading_helper.reap_threads
def test_json_mutating_list(self):
def worker(barrier, data, index):
barrier.wait()
Expand All @@ -48,6 +48,7 @@ def worker(barrier, data, index):
data = [[], []]
encode_json_helper(self.json, worker, data)

@threading_helper.reap_threads
def test_json_mutating_exact_dict(self):
def worker(barrier, data, index):
barrier.wait()
Expand All @@ -65,6 +66,7 @@ def worker(barrier, data, index):
data = [{}, {}]
encode_json_helper(self.json, worker, data)

@threading_helper.reap_threads
def test_json_mutating_mapping(self):
def worker(barrier, data, index):
barrier.wait()
Expand Down
Loading

Back | FazBrowse Home | New Git URL