-
Notifications
You must be signed in to change notification settings - Fork 228
Add no-GIL interpreter support #641
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
base: main
Are you sure you want to change the base?
Changes from all commits
6ced817
75cdd03
cafe4f0
3cc2a38
61aa23f
7b7b1bf
d965025
bf58057
42f4cba
d0797bd
79e5de1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
Cython~=3.1.2 | ||
#pytest-run-parallel[psutil] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#!/usr/bin/env python3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to #613 (comment), sharing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whatever works: I borrowed this test from another fork, and I'm still learning how to modernize existing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What I would do is install - name: Install pytest-run-parallel under free-threading
if: matrix.py == '3.14t-dev' || matrix.py == '3.13t'
shell: bash
run: |
pip install pytest-run-parallel
- name: Run tests in parallel under free-threading
if: matrix.py == '3.14t-dev' || matrix.py == '3.13t'
shell: bash
run: |
pytest -v --parallel-threads=auto --iterations=20 test |
||
import threading | ||
from concurrent.futures import ThreadPoolExecutor | ||
|
||
from msgpack import Packer | ||
|
||
|
||
def run_threaded( | ||
func, | ||
num_threads=8, | ||
pass_count=False, | ||
pass_barrier=False, | ||
outer_iterations=1, | ||
prepare_args=None, | ||
): | ||
"""Runs a function many times in parallel""" | ||
for _ in range(outer_iterations): | ||
with ThreadPoolExecutor(max_workers=num_threads) as tpe: | ||
if prepare_args is None: | ||
args = [] | ||
else: | ||
args = prepare_args() | ||
if pass_barrier: | ||
barrier = threading.Barrier(num_threads) | ||
args.append(barrier) | ||
if pass_count: | ||
all_args = [(func, i, *args) for i in range(num_threads)] | ||
else: | ||
all_args = [(func, *args) for i in range(num_threads)] | ||
try: | ||
futures = [] | ||
for arg in all_args: | ||
futures.append(tpe.submit(*arg)) | ||
finally: | ||
if len(futures) < num_threads and pass_barrier: | ||
barrier.abort() | ||
for f in futures: | ||
f.result() | ||
|
||
|
||
def test_multithread_packing(): | ||
output = [] | ||
test_data = "abcd" * 10_000_000 | ||
packer = Packer() | ||
|
||
def closure(b): | ||
data = packer.pack(test_data) | ||
output.append(data) | ||
b.wait() | ||
|
||
run_threaded(closure, num_threads=10, pass_barrier=True, pass_count=False) |
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.
These also seem unrelated to the purpose of the PR (adding support for free-threading).
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.
Fixed lints as well in this PR