Skip to content
Prev Previous commit
Next Next commit
gh-120754: _pyio ensure _stat_atopen is cleared on fd change
  • Loading branch information
cmaloney committed Oct 8, 2024
commit d2cb36594dfddedcb773f597fbf3a6ec9a32e016
3 changes: 3 additions & 0 deletions Lib/_pyio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,7 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
"""
if self._fd >= 0:
# Have to close the existing file first.
self._stat_atopen = None
try:
if self._closefd:
os.close(self._fd)
Expand Down Expand Up @@ -1585,6 +1586,7 @@ def __init__(self, file, mode='r', closefd=True, opener=None):
except:
if owned_fd is not None:
os.close(owned_fd)
self._stat_atopen = None
raise
self._fd = fd

Expand Down Expand Up @@ -1756,6 +1758,7 @@ def close(self):
called more than once without error.
"""
if not self.closed:
self._stat_atopen = None
try:
if self._closefd:
os.close(self._fd)
Expand Down