[PATCH] chgserver: remove Python 2 file descriptor logic
Yuya Nishihara
yuya at tcha.org
Fri Mar 4 02:12:09 UTC 2022
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1646357326 -32400
# Fri Mar 04 10:28:46 2022 +0900
# Node ID 3a9729bead90ef7caaf4d25138680c83a888be78
# Parent 46b3ecfb16e2781ede9752d972dc22f0e1dfea87
chgserver: remove Python 2 file descriptor logic
Follows up 0bb28b7736bc "chgserver: remove Python 2 support code."
On Python 2, we had to close newfp prior to restoring the original file
description since "delete newfp" would otherwise close the file descriptor
shared with the long-lived fp:
in attachio():
newfp = os.fdopen(fp.fileno(), mode, bufsize)
in _restoreio():
newfp.close() # temporarily close newfp.fileno() (= fp.fileno())
os.dup2(fd, fp.fileno()) # reopen fp.fileno() with original fd
On the other hand, we shouldn't call newfp.close() on Python 3 since
any function calls are proxied to the underlying file object by
procutil.LineBufferedWrapper.
diff --git a/mercurial/chgserver.py b/mercurial/chgserver.py
--- a/mercurial/chgserver.py
+++ b/mercurial/chgserver.py
@@ -438,14 +438,8 @@ class chgcmdserver(commandserver.server)
nullfd = os.open(os.devnull, os.O_WRONLY)
ui = self.ui
for (ch, fp, fd), (cn, fn, mode) in zip(self._oldios, _iochannels):
- newfp = getattr(ui, fn)
- # On Python 3, newfp is just a wrapper around fp even if newfp is
- # not fp, so deleting newfp is safe.
- if newfp is not fp:
- newfp.close()
- # restore original fd: fp is open again
try:
- if newfp is fp and 'w' in mode:
+ if 'w' in mode:
# Discard buffered data which couldn't be flushed because
# of EPIPE. The data should belong to the current session
# and should never persist.
More information about the Mercurial-devel
mailing list