From fe11c1e4980d94e2448adfbebec1bf65dab56b9d Mon Sep 17 00:00:00 2001 From: Jacob Nevins Date: Mon, 24 Oct 2022 12:45:37 +0100 Subject: [PATCH] authplugin-example.py: Flush stderr. Python 3's stderr was fully-buffered when non-interactive, unlike Python 2 and more or less everything else, until 3.9 in 2020(!): https://bugs.python.org/issue13601 (It would be less faff to sys.stderr.reconfigure(line_buffering=True) at the start, but that was only added in 3.7, whereas the 'flush' argument to print() dates back to 3.3, so I chose that to minimise the risk of version dependencies getting in the way of using this as a working example.) (cherry picked from commit 329a4cdd7942c441403374c19b0de287a67d21b7) --- contrib/authplugin-example.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/authplugin-example.py b/contrib/authplugin-example.py index 1fc27257..5932ad1a 100755 --- a/contrib/authplugin-example.py +++ b/contrib/authplugin-example.py @@ -136,7 +136,8 @@ def protocol(): hostname = rd_string_utf8(msg) port = rd_uint32(msg) username = rd_string_utf8(msg) - print(f"Got hostname {hostname!r}, port {port!r}", file=sys.stderr) + print(f"Got hostname {hostname!r}, port {port!r}", file=sys.stderr, + flush=True) # Decide which protocol version we're speaking. version = min(their_version, our_max_version) @@ -281,7 +282,7 @@ def protocol(): # Demonstration write to stderr, to prove that it shows up in PuTTY's # Event Log. -print("Hello from test plugin's stderr", file=sys.stderr) +print("Hello from test plugin's stderr", file=sys.stderr, flush=True) try: protocol()