[issue26039] More flexibility in zipfile interface

Thomas Kluyver report at bugs.python.org
Wed Feb 24 09:50:57 EST 2016


Thomas Kluyver added the comment:

My initial patch would have allowed passing a readable file-like object into zipfile. I was persuaded that allowing ZipFile.open() to return a writable object was a more intuitive and flexible API.

Concurrent writes with zf.open(mode='w') should be impossible, because it only allows one open handle at a time. It still uses the lock inside _ZipWriteFile, so concurrent writes to a single handle should be serialised.

I would not recommend anyone try to do concurrent access to a single ZipFile object from multiple threads or coroutines. It's quite stateful, there is no mention of concurrency in the docs, and no tests I can see that try concurrent access. The only thing that might be safe is reading from two files inside the zip file (which shouldn't be changed by this), but I wouldn't want to guarantee even that.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26039>
_______________________________________


More information about the Python-bugs-list mailing list