Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-116738: Make bisect module thread-safe#137021
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import unittest | ||
| from itertools import cycle | ||
| from test.support import import_helper, threading_helper, subTests | ||
| from test.support.threading_helper import run_concurrently | ||
| bisect = import_helper.import_module("bisect") | ||
| NTHREADS = 10 | ||
| @threading_helper.requires_working_threading() | ||
| class TestBisect(unittest.TestCase): | ||
| @subTests("insort_func", [bisect.insort_left, bisect.insort_right]) | ||
| def test_racing_insort(self, insort_func): | ||
| lst = list(range(10)) | ||
| insort_items_iter = cycle(list(range(11))) | ||
| def worker(lst, insort_items_iter): | ||
| for _ in range(10): | ||
| insort_item = next(insort_items_iter) | ||
| insort_func(lst, insort_item) | ||
| run_concurrently( | ||
| worker_func=worker, | ||
| nthreads=NTHREADS, | ||
| args=(lst, insort_items_iter), | ||
| ) | ||
| self.assertTrue(self.is_sorted_ascending(lst)) | ||
| @staticmethod | ||
| def is_sorted_ascending(lst): | ||
| """ | ||
| Check if the list is sorted in ascending order (non-decreasing). | ||
| """ | ||
| return all(lst[i - 1] <= lst[i] for i in range(1, len(lst))) | ||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Make functions in :mod:`bisect` thread-safe on the :term:`free threaded | ||
| <free threading>` build. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be
import bisect?If I understand correctly,
import_helper.import_module()handles missing optional modules but that doesn't seem to be relevant here.