Martin Panter added the comment:

Thanks for the pointer Dhiraj. I prefer the open(mode="w") version proposed 
here, as being more flexible. This way you could wrap the writer object in e.g. 
TextIOWrapper. The other patch requires passing in a file reader object.

Having another look at zipfile-open-w4.patch, I have some thoughts about 
locking and the writing-while-reading restriction:

The lock seems to be designed to serialize reads and writes (which operate on 
the common underlying file object). See revision 4973ccd46e32, and 
<https://bugs.python.org/issue14099#msg234142>, although it would be good to 
document this, or at the minimum add a comment explaining the purpose and scope 
of the lock.

Currently, it appears that write() and writestr() acquire the lock, so I 
presume it is intended that these methods can be called multiple times 
concurrently, and also while the zip file is being read. With the patch, 
writestr() still preserves the lock usage, but write() does not because it is 
now implemented in terms of the new open(mode="w") method.

I think it would be good to clarify that the lock does _not_ protect concurrent 
writes via open(mode="w").

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue26039>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to