Skip to content

Commit 23152dd

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. When calling `dmypy restart` the `--timeout` option is also passed. Fix #88.
1 parent cac3c40 commit 23152dd

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
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: 20 additions & 3 deletions
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

@@ -377,7 +378,14 @@ def get_diagnostics(
377378
errors.strip(),
378379
)
379380
subprocess.run(
380-
["dmypy", "--status-file", dmypy_status_file, "restart"],
381+
[
382+
"dmypy",
383+
"--status-file",
384+
dmypy_status_file,
385+
"--timeout",
386+
str(dmypy_timeout),
387+
"restart",
388+
],
381389
capture_output=True,
382390
**windows_flag,
383391
encoding="utf-8",
@@ -395,10 +403,19 @@ def get_diagnostics(
395403
exit_status,
396404
errors.strip(),
397405
)
398-
mypy_api.run_dmypy(["--status-file", dmypy_status_file, "restart"])
406+
mypy_api.run_dmypy(
407+
["--status-file", dmypy_status_file, "--timeout", str(dmypy_timeout), "restart"]
408+
)
399409

400410
# run to use existing daemon or restart if required
401-
args = ["--status-file", dmypy_status_file, "run", "--"] + apply_overrides(args, overrides)
411+
args = [
412+
"--status-file",
413+
dmypy_status_file,
414+
"run",
415+
"--timeout",
416+
str(dmypy_timeout),
417+
"--",
418+
] + apply_overrides(args, overrides)
402419
if dmypy_command:
403420
# dmypy exists on PATH or was provided by settings
404421
# -> use this dmypy

0 commit comments

Comments
 (0)