8
8
9
9
from localstack .aws .api .lambda_ import Arn
10
10
from localstack .config import LAMBDA_DEBUG_MODE , LAMBDA_DEBUG_MODE_CONFIG_PATH
11
- from localstack .services .plugins import SERVICE_PLUGINS
12
11
from localstack .utils .lambda_debug_mode .lambda_debug_mode_config import (
13
12
LambdaDebugConfig ,
14
13
LambdaDebugModeConfig ,
@@ -25,6 +24,7 @@ class LambdaDebugModeSession:
25
24
_configuration_file_path : Optional [str ]
26
25
_watch_thread : Optional [Thread ]
27
26
_initialised_event : Optional [Event ]
27
+ _stop_event : Optional [Event ]
28
28
_config : Optional [LambdaDebugModeConfig ]
29
29
30
30
def __init__ (self ):
@@ -34,6 +34,7 @@ def __init__(self):
34
34
self ._configuration_file_path = None
35
35
self ._watch_thread = None
36
36
self ._initialised_event = None
37
+ self ._stop_event = None
37
38
self ._config = None
38
39
39
40
# Lambda Debug Mode is not enabled: leave as disabled state and return.
@@ -56,6 +57,9 @@ def __init__(self):
56
57
# occur with no Debug configuration.
57
58
self ._initialised_event = Event ()
58
59
60
+ # Signals when a shutdown signal from the application is registered.
61
+ self ._stop_event = Event ()
62
+
59
63
self ._watch_thread = Thread (
60
64
target = self ._watch_logic , args = (), daemon = True , name = "LambdaDebugModeConfigWatch"
61
65
)
@@ -88,6 +92,11 @@ def ensure_running(self) -> None:
88
92
exception_str ,
89
93
)
90
94
95
+ def signal_stop (self ) -> None :
96
+ stop_event = self ._stop_event
97
+ if stop_event is not None :
98
+ stop_event .set ()
99
+
91
100
def _load_lambda_debug_mode_config (self ):
92
101
yaml_configuration_string = None
93
102
try :
@@ -145,8 +154,8 @@ def _watch_logic(self) -> None:
145
154
self ._load_lambda_debug_mode_config ()
146
155
self ._initialised_event .set ()
147
156
148
- # Monitor for file changes whilst the lambda service is running.
149
- while SERVICE_PLUGINS . is_running ( "lambda" ):
157
+ # Monitor for file changes whilst the application is running.
158
+ while not self . _stop_event . is_set ( ):
150
159
time .sleep (1 )
151
160
epoch_last_modified = self ._config_file_epoch_last_modified_or_now ()
152
161
if epoch_last_modified > epoch_last_loaded :
0 commit comments