Skip to content

Commit 449c842

Browse files
committed
Shutdown dmypy after a configurable timeout
We call `dmypy run` with the `--timeout` option so that the daemon will shut down automatically after specified delay of inactivity. The timeout value is configurable through `dmypy_timeout` option, it defaults to 60s. Fix #88.
1 parent cac3c40 commit 449c842

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Configuration
6060
- ``string``
6161
- **Specifies which status file dmypy should use**. This modifies the ``--status-file`` option passed to ``dmypy`` given ``dmypy`` is active.
6262
- ``.dmypy.json``
63+
* - ``dmypy_timeout``
64+
- ``pylsp.plugins.pylsp_mypy.dmypy_timeout``
65+
- ``string``
66+
- **Specifies the inactivity timeout after which the mypy daemon will automatically shut down**.
67+
- ``60``
6368
* - ``config_sub_paths``
6469
- ``pylsp.plugins.pylsp_mypy.config_sub_paths``
6570
- ``array`` of ``string`` items

pylsp_mypy/plugin.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def get_diagnostics(
293293

294294
if dmypy:
295295
dmypy_status_file = settings.get("dmypy_status_file", ".dmypy.json")
296+
dmypy_timeout = int(settings.get("dmypy_timeout", 60))
296297

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

@@ -398,7 +399,14 @@ def get_diagnostics(
398399
mypy_api.run_dmypy(["--status-file", dmypy_status_file, "restart"])
399400

400401
# run to use existing daemon or restart if required
401-
args = ["--status-file", dmypy_status_file, "run", "--"] + apply_overrides(args, overrides)
402+
args = [
403+
"--status-file",
404+
dmypy_status_file,
405+
"run",
406+
"--timeout",
407+
str(dmypy_timeout),
408+
"--",
409+
] + apply_overrides(args, overrides)
402410
if dmypy_command:
403411
# dmypy exists on PATH or was provided by settings
404412
# -> use this dmypy

0 commit comments

Comments
 (0)