pyexcel icon indicating copy to clipboard operation
pyexcel copied to clipboard

`free_resources()` fundamentally thread-unsafe?

Open risicle opened this issue 1 month ago • 1 comments

Would I be right in thinking pyexcel.free_resources() is fundamentally thread/async-unsafe by design?

Because it acts globally, it will close files across the process, not knowing whether another thread/context is still using a particular file. Another thread that has had its file closed will receive ValueError: I/O operation on closed file. when performing the next iteration cycle. This is particularly strange when the application opened the file in the first place and presumably expects to have the responsibility for closing it itself.

(pyexcel 0.7.4, pyexcel-io 0.6.7)

The only way I can see of using the current design "safely" is to have a global reader-writer lock, with functions parsing files holding onto a read-lock until they're done with their iterators and functions calling free_resources() requiring a write-lock to do so.

Or am I missing something?

risicle avatar Nov 21 '25 11:11 risicle

well, definitely is thread-unsafe.

chfw avatar Nov 21 '25 14:11 chfw