[issue37523] zipfile: Raise ValueError for i/o operations on closed zipfile.ZipExtFile
Daniel Hillier
report at bugs.python.org
Tue Oct 29 01:46:54 EDT 2019
Daniel Hillier <daniel.hillier at gmail.com> added the comment:
Here's the script I used for profiling and the results I observed with and without the closed check in read:
import zipfile
test_zip = "time_test.zip"
test_name = "test_name.txt"
with zipfile.ZipFile(test_zip, "w") as zf:
zf.writestr(test_name, "Hi there! " * 300)
with zipfile.ZipFile(test_zip) as zf:
for i in range(100000):
zf.read(test_name)
# Current code (no closed check), three different profiling sessions:
# ncalls tottime percall cumtime percall filename:lineno(function)
# 100000 0.612 0.000 6.638 0.000 zipfile.py:884(read)
# 100000 0.598 0.000 6.489 0.000 zipfile.py:884(read)
# 100000 0.600 0.000 6.485 0.000 zipfile.py:884(read)
# With closed check, three different profiling sessions:
# ncalls tottime percall cumtime percall filename:lineno(function)
# 100000 0.632 0.000 6.587 0.000 zipfile.py:884(read)
# 100000 0.623 0.000 6.564 0.000 zipfile.py:884(read)
# 100000 0.638 0.000 6.700 0.000 zipfile.py:884(read)
-------
I based this change on the what BytesIO does: https://github.com/python/cpython/blob/master/Lib/_pyio.py#L912
Let me know if you want me to make any changes.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37523>
_______________________________________
More information about the Python-bugs-list
mailing list