MCPcopy Index your code
hub / github.com/stemdeckapp/stemdeck / lifespan

Function lifespan

app/main.py:134–151  ·  view source on GitHub ↗
(_: FastAPI)

Source from the content-addressed store, hash-verified

132
133@asynccontextmanager
134async def lifespan(_: FastAPI) -> AsyncIterator[None]:
135 _background_tasks = set()
136 t = asyncio.create_task(_sweep_loop())
137 _background_tasks.add(t)
138 t.add_done_callback(_background_tasks.discard)
139 if os.environ.get("STEMDECK_DESKTOP") == "1":
140 parent_pid = os.environ.get("STEMDECK_PARENT_PID")
141 if parent_pid:
142 try:
143 parent_pid_int = int(parent_pid)
144 except ValueError:
145 _log.warning("invalid STEMDECK_PARENT_PID=%r", parent_pid)
146 else:
147 if parent_pid_int > 0 and parent_pid_int != os.getpid():
148 wt = asyncio.create_task(_desktop_parent_watchdog(parent_pid_int))
149 _background_tasks.add(wt)
150 wt.add_done_callback(_background_tasks.discard)
151 yield
152
153
154# Phones hitting the self-hosted server URL get the mobile UI; everything

Callers

nothing calls this directly

Calls 3

setFunction · 0.85
_sweep_loopFunction · 0.85
_desktop_parent_watchdogFunction · 0.85

Tested by

no test coverage detected