tests: Fix unclosed file in fd_check script

pull/1213/head
Alex Willmer 11 months ago
parent 67219c309a
commit 9342186b22

@ -25,6 +25,7 @@ In progress (unreleased)
* :gh:issue:`1111` :mod:`mitogen`: Replace uses of deprecated
:py:func:`pkgutil.find_loader`
* :gh:issue:`1213` :mod:`mitogen`: Fix unclosed file in first stage
* :gh:issue:`1213` tests: Fix unclosed file in fd_check script
v0.3.21 (2025-01-20)

@ -26,6 +26,7 @@ def controlling_tty():
return None
out_path = sys.argv[1]
fd = int(sys.argv[2])
st = os.fstat(fd)
@ -35,7 +36,7 @@ if sys.argv[3] == 'write':
else:
buf = os.read(fd, 4).decode()
open(sys.argv[1], 'w').write(repr({
output = repr({
'buf': buf,
'flags': fcntl.fcntl(fd, fcntl.F_GETFL),
'st_mode': st.st_mode,
@ -43,4 +44,21 @@ open(sys.argv[1], 'w').write(repr({
'st_ino': st.st_ino,
'ttyname': ttyname(fd),
'controlling_tty': controlling_tty(),
}))
})
try:
out_f = open(out_path, 'w')
except Exception:
exc = sys.exc_info()[1]
sys.stderr.write("Failed to open %r: %r" % (out_path, exc))
sys.exit(1)
try:
out_f.write(output)
except Exception:
out_f.close()
exc = sys.exc_info()[1]
sys.stderr.write("Failed to write to %r: %r" % (out_path, exc))
sys.exit(2)
out_f.close()

Loading…
Cancel
Save