You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Python] Dataset.to_batches() / ParquetFileFragment.to_batches() hang forever #45214
In the datasets library we are using ParquetFileFragment.to_batches() to stream batches of data while applying filters file-per-file. We create fragments from file-like objects (because files can be local or remote).
In the original issue in datasets this message was also reported:
Fatal Python error: PyGILState_Release: thread state 0x7fa1f409ade0 must be current when releasing
Python runtime state: finalizing (tstate=0x0000000000ad2958)
Thread 0x00007fa33d157740 (most recent call first):
<no Python frame>
Component(s)
Parquet, Python
Reacted by Ilya Lavrenov, Joel Bäcker, Tamerlan Tabolov, rakib-hasan, tom kelly, MarcusBluestone, Nicholas Goldowsky-Dill, Connor Brinton and Keegan Quigley
changed the title [-][Python] ParquetFragment.to_batches() hangs forever[/-][+][Python] ParquetFileFragment.to_batches() hangs forever[/+]on Jan 9, 2025
changed the title [-][Python] ParquetFileFragment.to_batches() hangs forever[/-][+][Python] Dataset.to_batches() / ParquetFileFragment.to_batches() hang forever[/+]on Apr 24, 2025
Has there be any update on this by any chance ? I'm also happy to try out ideas if you think there is a workaround (maybe wrapping the reader and wait for it to be ready for deletion or something like that ?)
I did some testing. It appears that this only happens when calling with filesystem=HfFileSystem(). The program exits normally when using a file on disk. Additionally, when using the HF filesystem, if I pass use_threads=False when calling to_batches, the program hung for a long time but eventually exited.
I am really familiar with Cython and async C++ though.
Activity
[-][Python] ParquetFragment.to_batches() hangs forever[/-][+][Python] ParquetFileFragment.to_batches() hangs forever[/+]lhoestq commentedon Apr 24, 2025
This also causes
pyarrow.dataset.Dataset.to_batches()to make the python script hang at the end:PS: if you run in ipython, call
exit()to observe the hanging[-][Python] ParquetFileFragment.to_batches() hangs forever[/-][+][Python] Dataset.to_batches() / ParquetFileFragment.to_batches() hang forever[/+]pitrou commentedon Apr 28, 2025
Given that we're talking about a hang or crash when destroying a partially read dataset, this could be the same as #43604
Unfortunately, my attempt at fixing it hit other issues: #43756
lhoestq commentedon Oct 15, 2025
Has there be any update on this by any chance ? I'm also happy to try out ideas if you think there is a workaround (maybe wrapping the reader and wait for it to be ready for deletion or something like that ?)
fix(data): bypass load_dataset() to fix HF Spaces streaming hang and OOM
fix(data): bypass load_dataset() to fix HF Spaces streaming hang and …
liningpan commentedon Dec 27, 2025
I did some testing. It appears that this only happens when calling with
filesystem=HfFileSystem(). The program exits normally when using a file on disk. Additionally, when using the HF filesystem, if I passuse_threads=Falsewhen callingto_batches, the program hung for a long time but eventually exited.I am really familiar with Cython and async C++ though.
lhoestq commentedon May 4, 2026
Here is another reproducible example using pyarrow 24.0.0 that was shared in huggingface/huggingface_hub#4178:
which prints this and then hangs
a workaround could be to
delthe fragment iterator instead of relying on gc, will try it outpitrou commentedon May 5, 2026
Is it possible to get a C-level backtrace of where the hang happens?
lhoestq commentedon May 6, 2026
here is the backtrace for the last example I shared (comment)
pitrou commentedon May 6, 2026
Hmm, can you post the tracebacks for all threads? (that would be
thread apply all btwith gdb, not sure about lldb)lhoestq commentedon May 6, 2026
I used
bt allwhich shows the info for all threads, am I missing something ? 👀pitrou commentedon May 6, 2026
Oops, sorry, I had misread. I was expecting the output to be much larger visually 😳
pitrou commentedon May 6, 2026
Hmm, on Ubuntu and Python 3.10 I get a crash with the original reproducer, rather than a hang.
pitrou commentedon May 6, 2026
I've submitted #49943 which fixes the original reproducer for me on Linux, but I have no idea whether it'll work on macOS or fix the other snippets.
lhoestq commentedon May 6, 2026
I built PyArrow from your PR and it does fix the issue on my side for all three snippets ! 🥳
pitrou commentedon May 6, 2026
Ah, interesting. Thanks for testing!
GH-49942: [Python] Protect PyBuffer and NumPyBuffer destructors again…
apacheGH-49942: [Python] Protect PyBuffer and NumPyBuffer destructors…
End commands with run_and_exit, so that leaving a stream does not hang