Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enable CPython free-threaded wheel builds #301

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

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

andfoy
Copy link

@andfoy andfoy commented Mar 17, 2025

Fixes #292

This PR enables support for free-threading builds of python-lz4, in particular this diff achieves the following goals:

  • Checking that the test suite is free-threading compliant by using pytest-run-parallel, which executes each test in a concurrent fashion. Such check did not raise any major concurrency issues related neither to race conditions nor memory manipulation that could lead to segfaults. The only tests marked to be single-threaded were the ones related to check for memory usage.
  • Testing, building, packaging and publishing free-threaded wheels via CI
  • Marking each C module as free-threaded compatible
  • Checking that there are no major C thread issues using Thread Sanitizer (TSAN)

Overall, this package does not have any major C threading issues, given that the underlying library is thread safe lz4/lz4#887 (comment) (at least when each thread owns its own compression/decompression context).

@jonathanunderwood
Copy link
Member

Thanks for this. I have kicked off the tests.

I plan to merge #300 ahead of this, so we'll probably need to rebase this one at that oint.

@andfoy andfoy force-pushed the support_free_threaded branch from 6362419 to 739aaec Compare April 3, 2025 17:24
run: |
echo "CIBW_BEFORE_TEST=pip install pytest pytest-run-parallel" >> "$GITHUB_ENV"
echo "CIBW_ENVIRONMENT=PYLZ4_USE_SYSTEM_LZ4=False PYTEST_ADDOPTS=--parallel-threads=4" >> "$GITHUB_ENV"
echo "CIBW_TEST_COMMAND=tox -x testenv.deps+=pytest-run-parallel -x testenv.pass_env+=PYTEST_ADDOPTS -c {project}" >> "$GITHUB_ENV"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't these be better set with an env stanza? If they must be set this way, please add a comment explaining why.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The echo "VAR=VALUE" >> "$GITHUB_ENV" is the standard preferred way to set variables in Github Actions workflows: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#passing-values-between-steps-and-jobs-in-a-workflow

env:
CIBW_ENVIRONMENT: PYLZ4_USE_SYSTEM_LZ4="False"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this for non free threading builds? We definitely don't want to use the system LZ4 library in all cases, so I am a little confused on the thinking here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable was absorbed by the redefinition over at line 71

CIBW_BUILD: ${{ matrix.cibw_build }}
CIBW_SKIP: "cp*-musllinux*"
CIBW_TEST_COMMAND: "tox -c {project}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this removed in the general case?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual command was moved to its own definition over at lines 73 and 79

def test_2(data, mode, store_size, dictionary):
(c_kwargs, d_kwargs) = setup_kwargs(mode, store_size)

data_in = [data for i in range(32)]
def copy_buf(data):
data_x = data
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should really go into an else clause on the following conditional.

@rgommers
Copy link

This all looks pleasantly clean, it'd be nice to move this forward.

Checking that there are no major C thread issues using Thread Sanitizer (TSAN)

This seems to be the one open TODO item - were you able to try this by any chance @andfoy?

@andfoy
Copy link
Author

andfoy commented Apr 28, 2025

@rgommers @jonathanunderwood I've just checked, and there are no TSAN errors when running the test suite in parallel

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support free threaded builds
3 participants