comparison mercurial/utils/procutil.py @ 45852:b56feaa9b520

chgserver: backport py3 buffered I/O workarounds from procutil I've recently switched to new machine and I found chg's stdout is fully buffered. Even though chg server is a daemon process, it inherits the environment where the chg client originally forked the server. This means the server's stdout might have been wrapped by LineBufferedWrapper. That's why we need to do wrap/unwrap in both ways. The "if" condition in _restoreio() looks weird, but I'm not willing to clean things up because stdio behavior is fundamentally different between py2 and py3, and py2 support will be dropped anyway.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 17 Nov 2020 19:29:08 +0900
parents 37c65704869d
children 89a2afe31e82
comparison
equal deleted inserted replaced
45847:d68618954ade 45852:b56feaa9b520
76 # to emulate line buffering. 76 # to emulate line buffering.
77 return stream 77 return stream
78 if isinstance(stream, LineBufferedWrapper): 78 if isinstance(stream, LineBufferedWrapper):
79 return stream 79 return stream
80 return LineBufferedWrapper(stream) 80 return LineBufferedWrapper(stream)
81
82
83 def unwrap_line_buffered(stream):
84 if isinstance(stream, LineBufferedWrapper):
85 assert not isinstance(stream.orig, LineBufferedWrapper)
86 return stream.orig
87 return stream
81 88
82 89
83 class WriteAllWrapper(object): 90 class WriteAllWrapper(object):
84 def __init__(self, orig): 91 def __init__(self, orig):
85 self.orig = orig 92 self.orig = orig