Skip to content

Commit

Permalink
remote/coordinator: add names for asyncio tasks
Browse files Browse the repository at this point in the history
This helps with debugging, as tasks don't use the default names of
"Task-<ID>".

Signed-off-by: Jan Luebbe <jlu@pengutronix.de>
  • Loading branch information
jluebbe committed Nov 22, 2024
1 parent a919c66 commit f9d9992
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions labgrid/remote/coordinator.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def __init__(self) -> None:
self.load()

self.loop = asyncio.get_running_loop()
self.poll_task = self.loop.create_task(self.poll())
self.poll_task = self.loop.create_task(self.poll(), name="coordinator-poll")

async def _poll_step(self):
# save changes
Expand Down Expand Up @@ -298,6 +298,7 @@ async def request_task():
name = in_msg.startup.name
session = self.clients[peer] = ClientSession(self, peer, name, out_msg_queue, version)
logging.debug("Received startup from %s with %s", name, version)
asyncio.current_task().set_name(f"client-{peer}-rx/started-{name}")
elif kind == "subscribe":
if in_msg.subscribe.all_places:
session.subscribe_places()
Expand All @@ -309,7 +310,8 @@ async def request_task():
except Exception:
logging.exception("error in client message handler")

running_request_task = self.loop.create_task(request_task())
asyncio.current_task().set_name(f"client-{peer}-tx")
running_request_task = self.loop.create_task(request_task(), name=f"client-{peer}-rx/init")

try:
async for out_msg in queue_as_aiter(out_msg_queue):
Expand Down Expand Up @@ -389,6 +391,7 @@ async def request_task():
session = self.exporters[peer] = ExporterSession(self, peer, name, command_queue, version)
logging.debug("Exporters: %s", self.exporters)
logging.debug("Received startup from %s with %s", name, version)
asyncio.current_task().set_name(f"exporter-{peer}-rx/started-{name}")
elif kind == "resource":
logging.debug("Received resource from %s with %s", name, in_msg.resource)
action, _ = session.set_resource(
Expand All @@ -405,7 +408,8 @@ async def request_task():
except Exception:
logging.exception("error in exporter message handler")

running_request_task = self.loop.create_task(request_task())
asyncio.current_task().set_name(f"exporter-{peer}-tx")
running_request_task = self.loop.create_task(request_task(), name=f"exporter-{peer}-rx/init")

try:
async for cmd in queue_as_aiter(command_queue):
Expand Down Expand Up @@ -958,6 +962,7 @@ async def GetReservations(self, request: labgrid_coordinator_pb2.GetReservations


async def serve(listen, cleanup) -> None:
asyncio.current_task().set_name(f"coordinator-serve")
# It seems since https://github.com/grpc/grpc/pull/34647, the
# ping_timeout_ms default of 60 seconds overrides keepalive_timeout_ms,
# so set it as well.
Expand Down

0 comments on commit f9d9992

Please sign in to comment.