Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show dmypy errors post serving #16250

Merged
merged 1 commit into from
Oct 12, 2023
Merged

Conversation

svalentin
Copy link
Collaborator

@svalentin svalentin commented Oct 11, 2023

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.

term1$ python3 -m mypy.dmypy daemon

term2$ python3 -m mypy.dmypy check -v test.py
[... some output ...]

term1$ [Control-C]
^CTraceback (most recent call last):
  File "/home/svalentin/src/mypy-svalentin/mypy/dmypy_server.py", line 220, in serve
    with server:
  File "/home/svalentin/src/mypy-svalentin/mypy/ipc.py", line 232, in __enter__
    self.connection, _ = self.sock.accept()
  File "/usr/lib/python3.8/socket.py", line 292, in accept
    fd, addr = self._accept()
KeyboardInterrupt
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/svalentin/src/mypy-svalentin/mypy/dmypy/__main__.py", line 6, in <module>
    console_entry()
  File "/home/svalentin/src/mypy-svalentin/mypy/dmypy/client.py", line 748, in console_entry
    main(sys.argv[1:])
  File "/home/svalentin/src/mypy-svalentin/mypy/dmypy/client.py", line 275, in main
    args.action(args)
  File "/home/svalentin/src/mypy-svalentin/mypy/dmypy/client.py", line 629, in do_daemon
    Server(options, args.status_file, timeout=args.timeout).serve()
  File "/home/svalentin/src/mypy-svalentin/mypy/dmypy_server.py", line 220, in serve
    with server:
  File "/home/svalentin/src/mypy-svalentin/mypy/ipc.py", line 232, in __enter__
    self.connection, _ = self.sock.accept()
  File "/usr/lib/python3.8/socket.py", line 292, in accept
    fd, addr = self._accept()
KeyboardInterrupt

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.
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@svalentin svalentin requested a review from JukkaL October 11, 2023 22:32
@svalentin svalentin merged commit 2c1009e into python:master Oct 12, 2023
17 checks passed
@svalentin svalentin deleted the daemon-error branch October 12, 2023 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants