This repository was archived by the owner on Mar 23, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Expand file tree
/
Copy pathcurrent.py
More file actions
40 lines (30 loc) · 1.18 KB
/
Copy pathcurrent.py
File metadata and controls
40 lines (30 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""This package gives access to the singleton ``LocalstackRuntime`` instance. This is the only global state
that should exist within localstack, which contains the singleton ``LocalstackRuntime`` which is currently
running."""
import threading
import typing
if typing.TYPE_CHECKING:
# make sure we don't have any imports here at runtime, so it can be imported anywhere without conflicts
from .runtime import LocalstackRuntime
_runtime: typing.Optional["LocalstackRuntime"] = None
"""The singleton LocalStack Runtime"""
_runtime_lock = threading.RLock()
def get_current_runtime() -> "LocalstackRuntime":
with _runtime_lock:
if not _runtime:
raise ValueError("LocalStack runtime has not yet been set")
return _runtime
def set_current_runtime(runtime: "LocalstackRuntime"):
with _runtime_lock:
global _runtime
_runtime = runtime
def initialize_runtime() -> "LocalstackRuntime":
from localstack.runtime import runtime
with _runtime_lock:
try:
return get_current_runtime()
except ValueError:
pass
rt = runtime.create_from_environment()
set_current_runtime(rt)
return rt