Skip to content
This repository was archived by the owner on May 3, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion examples/EmergencyManagement/Server/server_emergency.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ async def main():
svc.add_route("PatchEvent", evc.PatchEvent, Event)
svc.add_route("RetrieveEvent", evc.RetrieveEvent)
svc.announce()
await svc.start()
service_task = asyncio.create_task(svc.start())
try:
await asyncio.sleep(30) # Run for 30 seconds then stop
finally:
await svc.stop()
await service_task

if __name__ == "__main__":
asyncio.run(main())
17 changes: 17 additions & 0 deletions reticulum_openapi/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, config_path: str = None, storage_path: str = None,
# Routing table: command -> (handler_coroutine, payload_type)
self._routes: Dict[str, (Callable, Optional[Type])] = {}
self._loop = asyncio.get_event_loop()
self._start_task: Optional[asyncio.Task] = None
self.auth_token = auth_token
self.max_payload_size = max_payload_size
RNS.log(f"LXMFService initialized (Identity hash: {RNS.prettyhexrep(self.source_identity.hash)})")
Expand Down Expand Up @@ -220,8 +221,24 @@ def announce(self):
async def start(self):
"""Run the service until cancelled."""
RNS.log("LXMFService started and listening for messages...")
self._start_task = asyncio.current_task()
try:
while True:
await asyncio.sleep(1)
except asyncio.CancelledError:
RNS.log("Service stopping (Cancelled)")
finally:
self.router.exit_handler()
self._start_task = None

async def stop(self):
"""Cancel the running service loop and shut down the router."""
if self._start_task is not None:
self._start_task.cancel()
try:
await self._start_task
except asyncio.CancelledError:
pass
else:
# If start wasn't called yet, ensure router cleanup
self.router.exit_handler()