p.stdin.close()
p.stdout.close()
# Demultiplex remote client's stderr (back to stdout/stderr).
- dmc = DemuxConn(p.stderr.fileno(), open(os.devnull, "wb"))
- for line in iter(dmc.readline, b''):
- out.write(line)
+ with DemuxConn(p.stderr.fileno(), open(os.devnull, "wb")) as dmc:
+ for line in iter(dmc.readline, b''):
+ out.write(line)
finally:
while 1:
# if we get a signal while waiting, we have to keep waiting, just
# FIXME: this protocol is totally lame and not at all future-proof.
# (Especially since we abort completely as soon as *anything* bad happens)
sys.stdout.flush()
- conn = Conn(byte_stream(sys.stdin), byte_stream(sys.stdout))
- lr = linereader(conn)
- with finalized(None, lambda _: repo and repo.close()), \
+ with Conn(byte_stream(sys.stdin), byte_stream(sys.stdout)) as conn, \
+ finalized(None, lambda _: repo and repo.close()), \
finalized(None, lambda _: suspended_w and suspended_w.close()):
+ lr = linereader(conn)
for _line in lr:
line = _line.strip()
if not line:
def close(self):
self._base_closed = True
- while self._read(65536): pass
+
+ def __enter__(self):
+ return self
+
+ def __exit__(self, exc_type, exc_value, tb):
+ with pending_raise(exc_value, rethrow=False):
+ self.close()
def __del__(self):
assert self._base_closed