Repository navigation
Conversation
These are expected to fail. ___Help needed___ to fix the failing free threaded builds.
|
@cclauss can you explain why you expect those tests to fail? ____________________ test_block_decompress_mem_usage[data0] ____________________
data = b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
@pytest.mark.thread_unsafe
def test_block_decompress_mem_usage(data):
tracemalloc = pytest.importorskip('tracemalloc')
tracemalloc.start()
compressed = lz4.block.compress(data)
prev_snapshot = None
for i in range(1000):
decompressed = lz4.block.decompress(compressed) # noqa: F841
if i % 100 == 0:
gc.collect()
snapshot = tracemalloc.take_snapshot()
if prev_snapshot:
stats = snapshot.compare_to(prev_snapshot, 'lineno')
> assert stats[0].size_diff < (1024 * 8)
E AssertionError: assert 18184 < (1024 * 8)
E + where 18184 = <StatisticDiff traceback=<Traceback (<Frame filename='/project/.tox/py/lib/python3.14t/site-packages/coverage/sysmon.py' lineno=348>,)> size=18184 (+18184) count=1 (+1)>.size_diff
compressed = b'\x00\x00\x10\x00\x1fa\x01\x00\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf...\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xf6Paaaaa'
data = b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
decompressed = b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
i = 200
prev_snapshot = <tracemalloc.Snapshot object at 0x33e83dec450>
snapshot = <tracemalloc.Snapshot object at 0x33e83decf90>
stats = [<StatisticDiff traceback=<Traceback (<Frame filename='/project/.tox/py/lib/python3.14t/site-packages/coverage/sysmon..../_internal/cpython-3.14.0rc3-nogil/lib/python3.14t/tracemalloc.py' lineno=498>,)> size=576 (+576) count=12 (+12)>, ...]
tracemalloc = <module 'tracemalloc' from '/opt/_internal/cpython-3.14.0rc3-nogil/lib/python3.14t/tracemalloc.py'>
tests/block/test_block_3.py:39: AssertionErrorThis test is the only failure (both on ubuntu and windows). I fail to see how free-threading can be expected to impact the memory usage of sequential operations. This test is decorated with |
|
Maybe we could just skip this test if the |
|
We should not be surprised when functions marked with def free_threading() -> bool:
return sys.version_info >= (3, 13) and not sys._is_gil_enabled()
@pytest.mark.xfail(free_threading(), reason="May fail without a Global Interpreter Lock") |
Added a conditional xfail marker to test_block_decompress_mem_usage to handle cases without a Global Interpreter Lock.
…l Interpreter Lock")
|
|
|
Note that the |
|
I think the failing test probably indicates that the memory usage pattern is different on 3.14t and the test failure is probably "real" in the sense that the upper bound is being violated for whatever reason. There were some pretty substantial changes to the free-threaded GC in 3.14t, maybe we're hitting a corner case? I'll see if Neil wants to take a closer look at this... @cclauss just because a test is marked as thread-unsafe doesn't mean that the test is expected to fail on the free-threaded build. Only that it is an inherently thread-unsafe test and should be run on one core when running under pytest-run-parallel. You can also tell pytest-run-parallel to skip thread-unsafe tests, but that's not the default. @ogrisel one thing that might help future readers to interpret the thread-unsafe markers is to also specify a reason. In this case, it would have something like: The reason will also get propagated to the verbose output, allowing people to see why an unsafe test is skipped. We should probably make pytest-run-parallel warn when people use the thread-unsafe marker without a reason. I tried to figure out how to do that at one point but got stuck and haven't come back to it. |
ogrisel
left a comment
There was a problem hiding this comment.
LGTM as it is. The test failure on ubuntu and windows with free-threading might be revealing a real problem w.r.t. memory usage expectations, but it's indeed hard to tell, as @ngoldbaum explained above. I could not trigger the problem locally on macOS to investigate myself.
However, the core functionality of lz4 seems to work as expected on cp314t, so I would not condition the merge of this PR to the results of the investigation of the higher than expected memory usage reported by tracemalloc in this test.
Having cp314t wheels for python-lz4 would make it easier for downstream projects to get their own CI running on cp314t and subsequently unlock free-threading adoption throughout the Python ecosystem.
|
@jonathanunderwood @smorin @ngoldbaum Can I please get your reviews on this PR and #317 so that we can get a new release on PyPI that supports Python 3.14? |
%
uvx --with=lz4 python3.14t -c"import lz4"These are expected to fail. Help needed to fix the failing free threaded builds.
https://py-free-threading.github.io/porting
Related: