From 68910d50b05b06bdbcc55ca8741999eb142bed87 Mon Sep 17 00:00:00 2001 From: Valentin Stanciu <250871+svalentin@users.noreply.github.com> Date: Wed, 11 Oct 2023 19:38:36 +0000 Subject: [PATCH] show dmypy errors post serving After dmypy starts serving, stdout and stderr gets captured. If we have an error, we assume we can send it to the client. However, if we have an error outside of client communication, that error is lost. The easiest way to see this is to run dmypy in daemonize mode, run a check once, then Control-C to send a KeyboardInterrupt. That exception is not printed though it should. After this change you can clearly see it. --- mypy/dmypy_server.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mypy/dmypy_server.py b/mypy/dmypy_server.py index a50ebc5415ba9..faa9a23fadfb7 100644 --- a/mypy/dmypy_server.py +++ b/mypy/dmypy_server.py @@ -210,6 +210,8 @@ def serve(self) -> None: """Serve requests, synchronously (no thread or fork).""" command = None server = IPCServer(CONNECTION_NAME, self.timeout) + orig_stdout = sys.stdout + orig_stderr = sys.stderr try: with open(self.status_file, "w") as f: json.dump({"pid": os.getpid(), "connection_name": server.connection_name}, f) @@ -252,6 +254,10 @@ def serve(self) -> None: reset_global_state() sys.exit(0) finally: + # Revert stdout/stderr so we can see any errors. + sys.stdout = orig_stdout + sys.stderr = orig_stderr + # If the final command is something other than a clean # stop, remove the status file. (We can't just # simplify the logic and always remove the file, since