[issue41350] Use of zipfile.Path causes attempt to write after ZipFile is closed

2020-07-20 Thread Nick Henderson


New submission from Nick Henderson :

In both Python 3.8.3 and 3.9.0b3, using zipfile.Path to write a file in a 
context manager results in an attempt to write to the zip file after it is 
closed.

In Python 3.9.0b3:

import io
from zipfile import ZipFile, Path

def make_zip():
"""Make zip file and return bytes."""
bytes_io = io.BytesIO()
zip_file = ZipFile(bytes_io, mode="w")
zip_path = Path(zip_file, "file-a")

# use zipp.Path.open
with zip_path.open(mode="wb") as fp:
fp.write(b"contents of file-a")

zip_file.close()

data = bytes_io.getvalue()

bytes_io.close()

return data

zip_data = make_zip()
# Exception ignored in: 
# Traceback (most recent call last):
#   File "/Users/nick/.pyenv/versions/3.9.0b3/lib/python3.9/zipfile.py", line 
1807, in __del__
# self.close()
#   File "/Users/nick/.pyenv/versions/3.9.0b3/lib/python3.9/zipfile.py", line 
1824, in close
# self.fp.seek(self.start_dir)
# ValueError: I/O operation on closed file.


In Python 3.8.3:

import io
from zipfile import ZipFile, Path

def make_zip():
"""Make zip file and return bytes."""
bytes_io = io.BytesIO()
zip_file = ZipFile(bytes_io, mode="w")
zip_path = Path(zip_file, "file-a")

# use zipp.Path.open
with zip_path.open(mode="w") as fp:
fp.write(b"contents of file-a")

zip_file.close()

data = bytes_io.getvalue()

bytes_io.close()

return data

zip_data = make_zip()
# Exception ignored in: 
# Traceback (most recent call last):
#   File "/Users/nick/.pyenv/versions/3.8.3/lib/python3.8/zipfile.py", line 
1820, in __del__
# self.close()
#   File "/Users/nick/.pyenv/versions/3.8.3/lib/python3.8/zipfile.py", line 
1837, in close
# self.fp.seek(self.start_dir)
# ValueError: I/O operation on closed file.

In the Python 3.8 example, mode="w" is used in the open method on zip_path.

--
components: Library (Lib)
files: zippath_bug_39.py
messages: 374015
nosy: Nick Henderson
priority: normal
severity: normal
status: open
title: Use of zipfile.Path causes attempt to write after ZipFile is closed
type: behavior
versions: Python 3.8, Python 3.9
Added file: https://bugs.python.org/file49329/zippath_bug_39.py

___
Python tracker 
<https://bugs.python.org/issue41350>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37790] subprocess.Popen() is extremely slow

2019-09-08 Thread Nick Henderson


Nick Henderson  added the comment:

We have recently bumped into a similar problem. Using FreeBSD, subprocess calls 
were taking more than 10 times the usual time to execute after migrating to 
python3.6. After some digging, the default for 'close_fds' was changed to 
'True'. On linux, this actually made things faster, but for unix, much slower. 
Passing 'close_fds=False' solved this for us.

--
nosy: +nickhendo

___
Python tracker 
<https://bugs.python.org/issue37790>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com