Skip to content

Commit c9ec0fc

Browse files
committed
Add ability to configure traits via envs
1 parent 37a0bf2 commit c9ec0fc

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

jupyter_server/services/kernelspecs/kernelspec_cache.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,15 @@ def _cache_enabled_default(self):
5151

5252
kernel_spec_manager = Instance("jupyter_client.kernelspec.KernelSpecManager")
5353

54+
monitor_name_env = "JUPYTER_KERNELSPEC_MONITOR_NAME"
5455
monitor_name = Unicode(
55-
help="""The name of the entry_point used to monitor changes to kernelspecs.""",
56+
help="""The name of the entry_point used to monitor changes to kernelspecs.
57+
(JUPYTER_KERNELSPEC_MONITOR_NAME env var)""",
5658
).tag(config=True)
5759

5860
@default("monitor_name")
5961
def _monitor_name_default(self):
60-
return "polling-monitor"
62+
return os.getenv(self.monitor_name_env, "polling-monitor")
6163

6264
# The kernelspec cache consists of a dictionary mapping the kernel name to the actual
6365
# kernelspec data (CacheItemType).

jupyter_server/services/kernelspecs/monitors/polling_monitor.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
"""KernelSpec watchdog monitor used by KernelspecCache."""
22
# Copyright (c) Jupyter Development Team.
33
# Distributed under the terms of the Modified BSD License.
4-
54
import json
5+
import os
66
from hashlib import md5
77

88
from overrides import overrides
9-
from traitlets.traitlets import Float
9+
from traitlets.traitlets import Float, default
1010

1111
from ..kernelspec_cache import KernelSpecCache, KernelSpecMonitorBase
1212

1313

1414
class KernelSpecPollingMonitor(KernelSpecMonitorBase):
1515
"""Polling monitor that uses a periodic poll period to reload the kernelspec cache."""
1616

17+
interval_env = "JUPYTER_POLLING_MONITOR_INTERVAL"
1718
interval = Float(
18-
default_value=30.0,
1919
config=True,
20-
help="""The interval (in seconds) at which kernelspecs are updated in the cache.""",
20+
help="""The interval (in seconds) at which kernelspecs are updated in the cache.
21+
(JUPYTER_POLLING_MONITOR_INTERVAL env var)""",
2122
)
2223

24+
@default("interval")
25+
def _interval_default(self):
26+
return float(os.getenv(self.interval_env, "30.0"))
27+
2328
_pcallback = None
2429

2530
# Keep track of hash values for each entry placed into the cache. This will lessen

0 commit comments

Comments
 (0)