Skip to content

Shutdown dmypy after a configurable timeout #104

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ Configuration
- ``string``
- **Specifies which status file dmypy should use**. This modifies the ``--status-file`` option passed to ``dmypy`` given ``dmypy`` is active.
- ``.dmypy.json``
* - ``dmypy_timeout``
- ``pylsp.plugins.pylsp_mypy.dmypy_timeout``
- ``string``
- **Specifies the inactivity timeout after which the mypy daemon will automatically shut down**.
- ``60``
* - ``config_sub_paths``
- ``pylsp.plugins.pylsp_mypy.config_sub_paths``
- ``array`` of ``string`` items
Expand Down
23 changes: 20 additions & 3 deletions pylsp_mypy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def get_diagnostics(

if dmypy:
dmypy_status_file = settings.get("dmypy_status_file", ".dmypy.json")
dmypy_timeout = int(settings.get("dmypy_timeout", 60))

args = ["--show-error-end", "--no-error-summary", "--no-pretty"]

Expand Down Expand Up @@ -377,7 +378,14 @@ def get_diagnostics(
errors.strip(),
)
subprocess.run(
["dmypy", "--status-file", dmypy_status_file, "restart"],
[
"dmypy",
"--status-file",
dmypy_status_file,
"restart",
"--timeout",
str(dmypy_timeout),
],
capture_output=True,
**windows_flag,
encoding="utf-8",
Expand All @@ -395,10 +403,19 @@ def get_diagnostics(
exit_status,
errors.strip(),
)
mypy_api.run_dmypy(["--status-file", dmypy_status_file, "restart"])
mypy_api.run_dmypy(
["--status-file", dmypy_status_file, "restart", "--timeout", str(dmypy_timeout)]
)

# run to use existing daemon or restart if required
args = ["--status-file", dmypy_status_file, "run", "--"] + apply_overrides(args, overrides)
args = [
"--status-file",
dmypy_status_file,
"run",
"--timeout",
str(dmypy_timeout),
"--",
] + apply_overrides(args, overrides)
if dmypy_command:
# dmypy exists on PATH or was provided by settings
# -> use this dmypy
Expand Down