Skip to content
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
14 changes: 10 additions & 4 deletions src/cfclient/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,23 +68,29 @@ def _task_done_callback(task: asyncio.Task[object]) -> None:
return
try:
task.result()
except DisconnectedError:
logger.debug("Task interrupted by disconnect: %s", task)
except Exception:
import traceback

traceback.print_exc()
os._exit(1)


async def _wrap_disconnected(coro: Coroutine[object, object, object]) -> None:
try:
await coro
except DisconnectedError:
logger.debug("Task interrupted by disconnect: %r", coro)


def create_task(coro: Coroutine[object, object, object]) -> asyncio.Task[object]:
Comment thread
gemenerik marked this conversation as resolved.
"""Schedule a coroutine as a task with automatic exception logging.

Use this instead of asyncio.ensure_future() to ensure exceptions
are logged immediately rather than silently swallowed.
are logged immediately rather than silently swallowed. DisconnectedError
is treated as a normal shutdown case and is logged at debug level only.
"""
Comment thread
gemenerik marked this conversation as resolved.
logger.debug(f"create_task: {coro}")
task = asyncio.ensure_future(coro)
task = asyncio.ensure_future(_wrap_disconnected(coro))
task.add_done_callback(_task_done_callback)
return task

Expand Down
2 changes: 0 additions & 2 deletions src/cfclient/ui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,6 @@ async def _stream_battery(self, cf: Crazyflie) -> None:
self._battery_signal.emit(
data.data["pm.vbat"], int(data.data["pm.state"])
)
except DisconnectedError:
pass
finally:
if stream is not None:
try:
Expand Down
2 changes: 0 additions & 2 deletions src/cfclient/ui/pose_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ async def _stream_loop(self, cf: Crazyflie) -> None:
data.data[self.LOG_NAME_ESTIMATE_YAW],
)
self.data_received_cb.call(self, self.pose)
except DisconnectedError:
pass
finally:
if stream is not None:
try:
Expand Down
2 changes: 0 additions & 2 deletions src/cfclient/ui/tabs/FlightTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,6 @@ async def _stream_motors(self, cf: Crazyflie) -> None:
while True:
data = await stream.next()
self._log_data_received(data.timestamp, data.data)
except DisconnectedError:
pass
finally:
if stream is not None:
try:
Expand Down
Loading