# HG changeset patch # User Gregory Szorc # Date 1579372634 28800 # Node ID 52f8b07ad2f9194f6c3e2a8666d1f0557341628a # Parent bf5a73243cd5cbe24432b082665064694db2a153 debugcommands: move away from line buffered output on binary stream Line buffering on binary file objects is apparently undefined behavior in Python and emits a RuntimeWarning on Python 3.8. See https://bugs.python.org/issue32236. This commit changes the I/O logging file descriptor from line buffered to unbuffered to work around this. I'm no fan of unbuffered I/O for performance reasons. But I don't think it is an issue here given the nature of the code. With this change, test-ssh-proto.t now passes on Python 3.8. Differential Revision: https://phab.mercurial-scm.org/D7948 diff -r bf5a73243cd5 -r 52f8b07ad2f9 mercurial/debugcommands.py --- a/mercurial/debugcommands.py Sat Jan 18 10:43:52 2020 -0800 +++ b/mercurial/debugcommands.py Sat Jan 18 10:37:14 2020 -0800 @@ -3218,16 +3218,19 @@ raise error.Abort(_(b'cannot use both --logiofd and --logiofile')) if opts[b'logiofd']: - # Line buffered because output is line based. + # Ideally we would be line buffered. But line buffering in binary + # mode isn't supported and emits a warning in Python 3.8+. Disabling + # buffering could have performance impacts. But since this isn't + # performance critical code, it should be fine. try: - logfh = os.fdopen(int(opts[b'logiofd']), 'ab', 1) + logfh = os.fdopen(int(opts[b'logiofd']), 'ab', 0) except OSError as e: if e.errno != errno.ESPIPE: raise # can't seek a pipe, so `ab` mode fails on py3 - logfh = os.fdopen(int(opts[b'logiofd']), 'wb', 1) + logfh = os.fdopen(int(opts[b'logiofd']), 'wb', 0) elif opts[b'logiofile']: - logfh = open(opts[b'logiofile'], b'ab', 1) + logfh = open(opts[b'logiofile'], b'ab', 0) s = wireprotoserver.sshserver(ui, repo, logfh=logfh) s.serve_forever()