comparison mercurial/debugcommands.py @ 44123:52f8b07ad2f9

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
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 18 Jan 2020 10:37:14 -0800
parents e685fac56693
children 0b475b0b0344
comparison
equal deleted inserted replaced
44122:bf5a73243cd5 44123:52f8b07ad2f9
3216 3216
3217 if opts[b'logiofd'] and opts[b'logiofile']: 3217 if opts[b'logiofd'] and opts[b'logiofile']:
3218 raise error.Abort(_(b'cannot use both --logiofd and --logiofile')) 3218 raise error.Abort(_(b'cannot use both --logiofd and --logiofile'))
3219 3219
3220 if opts[b'logiofd']: 3220 if opts[b'logiofd']:
3221 # Line buffered because output is line based. 3221 # Ideally we would be line buffered. But line buffering in binary
3222 # mode isn't supported and emits a warning in Python 3.8+. Disabling
3223 # buffering could have performance impacts. But since this isn't
3224 # performance critical code, it should be fine.
3222 try: 3225 try:
3223 logfh = os.fdopen(int(opts[b'logiofd']), 'ab', 1) 3226 logfh = os.fdopen(int(opts[b'logiofd']), 'ab', 0)
3224 except OSError as e: 3227 except OSError as e:
3225 if e.errno != errno.ESPIPE: 3228 if e.errno != errno.ESPIPE:
3226 raise 3229 raise
3227 # can't seek a pipe, so `ab` mode fails on py3 3230 # can't seek a pipe, so `ab` mode fails on py3
3228 logfh = os.fdopen(int(opts[b'logiofd']), 'wb', 1) 3231 logfh = os.fdopen(int(opts[b'logiofd']), 'wb', 0)
3229 elif opts[b'logiofile']: 3232 elif opts[b'logiofile']:
3230 logfh = open(opts[b'logiofile'], b'ab', 1) 3233 logfh = open(opts[b'logiofile'], b'ab', 0)
3231 3234
3232 s = wireprotoserver.sshserver(ui, repo, logfh=logfh) 3235 s = wireprotoserver.sshserver(ui, repo, logfh=logfh)
3233 s.serve_forever() 3236 s.serve_forever()
3234 3237
3235 3238