Repository navigation
Closed
Description
I just noticed that the last CI run on gh-301 contained a failure on the Windows cp313t (free-threading) job that was added. From this CI log:
if prev_snapshot:
stats = snapshot.compare_to(prev_snapshot, 'lineno')
> assert stats[0].size_diff < MEM_INCREASE_LIMIT
E AssertionError: assert 25848 < 25600
E + where 25848 = <StatisticDiff traceback=<Traceback (<Frame filename='C:\\Users\\runneradmin\\AppData\\Local\\pypa\\cibuildwheel\\Cach...t-cpython\\python-freethreaded.3.13.2\\tools\\Lib\\tracemalloc.py' lineno=125>,)> size=25848 (+25848) count=359 (+359)>.size_diff
Full pytest output:
_________________ test_frame_open_decompress_mem_usage[data0] _________________
data = b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
def test_frame_open_decompress_mem_usage(data):
tracemalloc = pytest.importorskip('tracemalloc')
tracemalloc.start()
with lz4.frame.open('test.lz4', 'w') as f:
f.write(data)
prev_snapshot = None
for i in range(1000):
with lz4.frame.open('test.lz4', 'r') as f:
decompressed = f.read() # 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 < MEM_INCREASE_LIMIT
E AssertionError: assert 25848 < 25600
E + where 25848 = <StatisticDiff traceback=<Traceback (<Frame filename='C:\\Users\\runneradmin\\AppData\\Local\\pypa\\cibuildwheel\\Cach...t-cpython\\python-freethreaded.3.13.2\\tools\\Lib\\tracemalloc.py' lineno=125>,)> size=25848 (+25848) count=359 (+359)>.size_diff
data = b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
decompressed = b'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'
f = <lz4.frame.LZ4FrameFile object at 0x000005DC06266F00>
i = 200
prev_snapshot = <tracemalloc.Snapshot object at 0x000005DBF4847D50>
snapshot = <tracemalloc.Snapshot object at 0x000005DBF48471B0>
stats = [<StatisticDiff traceback=<Traceback (<Frame filename='C:\\Users\\runneradmin\\AppData\\Local\\pypa\\cibuildwheel\\Cac...t-cpython\\python-freethreaded.3.13.2\\tools\\Lib\\tracemalloc.py' lineno=503>,)> size=816 (+816) count=17 (+17)>, ...]
tracemalloc = <module 'tracemalloc' from 'C:\\Users\\runneradmin\\AppData\\Local\\pypa\\cibuildwheel\\Cache\\nuget-cpython\\python-freethreaded.3.13.2\\tools\\Lib\\tracemalloc.py'>
tests\frame\test_frame_5.py:90: AssertionError
=============================== tests coverage ================================
_______________ coverage: platform win32, python 3.13.2-final-0 _______________
Name Stmts Miss Cover
-------------------------------------------
lz4\block\__init__.py 1 0 100%
lz4\frame\__init__.py 245 47 81%
-------------------------------------------
TOTAL 246 47 81%
=========================== short test summary info ===========================
FAILED tests/frame/test_frame_5.py::test_frame_open_decompress_mem_usage[data0]
!!!!!!!!!!!!!!!!!!!!!!!!!! stopping after 1 failures !!!!!!!!!!!!!!!!!!!!!!!!!!
================= 1 failed, 19015 passed in 515.47s (0:08:35) =================
SystemError: deallocated bytearray object has exported buffers
Here is the test code:
python-lz4/tests/frame/test_frame_5.py
Lines 71 to 92 in 022d538
| def test_frame_open_decompress_mem_usage(data): | |
| tracemalloc = pytest.importorskip('tracemalloc') | |
| tracemalloc.start() | |
| with lz4.frame.open('test.lz4', 'w') as f: | |
| f.write(data) | |
| prev_snapshot = None | |
| for i in range(1000): | |
| with lz4.frame.open('test.lz4', 'r') as f: | |
| decompressed = f.read() # 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 < MEM_INCREASE_LIMIT | |
| prev_snapshot = snapshot |
There are a couple of potential issues:
- The GC behavior is quite different in a free-threaded interpreter, and I'm not sure that the test is supposed to always pass
tracemallocandbytearrayare involved, and they may not yet have been made thread-safe under parallel testing (I'm fairly sure that's true ofbytearrayas of today), so the test may be flaky.
@nascheme could I ask for your GC-expert opinion on that test please?
Metadata
Metadata
Assignees
Labels
No labels
Activity
nascheme commentedon Jun 3, 2025
After spending some time trying to reproduce this, I decided to engage my brain instead. :-) The problem is that the tracemalloc stats are a global interpreter property and so other threads allocating memory will influence the result. This test will then randomly fail depending on how much memory other threads allocate. If possible, this test should be excluded from running under parallel testing.
ngoldbaum commentedon Jun 11, 2025
The tests in that file should already be skipped under pytest-run-parallel:
https://github.com/python-lz4/python-lz4/blob/master/tests/frame/test_frame_5.py#L11
That said, the CI run was using pytest-run-parallel 0.3.1, so maybe it hit an issue we fixed in the pytest plugin. When I run the tests locally using pytest-run-parallel 0.4.4 all the tests in
test_frame_5.pyare skipped in parallel:rgommers commentedon Jun 16, 2025
Thanks for the feedback @nascheme and for testing that it passes with latest
pytest-run-parallel@ngoldbaum.I re-ran the Windows wheel builds on my fork, and they passed now: CI log. So I'll close this issue.