Skip to content

Catch DisconnectedError in create_task wrapper instead of per-coroutine#806

Open
gemenerik wants to merge 3 commits intoAris/cflib2/DisconnectedErrorfrom
rik/cflib2/DisconnectedError
Open

Catch DisconnectedError in create_task wrapper instead of per-coroutine#806
gemenerik wants to merge 3 commits intoAris/cflib2/DisconnectedErrorfrom
rik/cflib2/DisconnectedError

Conversation

@gemenerik
Copy link
Copy Markdown
Member

The existing _task_done_callback was meant to catch DisconnectedError for all tasks created via create_task, but PySide6's QtAsyncio logs unhandled task exceptions before done callbacks run. So the callback did catch the error (preventing os._exit), but the traceback was already printed. By wrapping the coroutine inside create_task, the exception is caught before it ever leaves the coroutine, so PySide6 never sees it. This also removes the now-redundant per-coroutine except DisconnectedError: pass blocks and the dead except DisconnectedError from _task_done_callback.

PySide6's QtAsyncio prints tracebacks for unhandled task exceptions
before done callbacks run, so the existing _task_done_callback catch
was too late. Wrap coroutines in create_task to catch DisconnectedError
before it reaches PySide6, and remove the now-redundant per-coroutine
except blocks.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR changes how DisconnectedError is handled for background asyncio tasks to avoid PySide6/QtAsyncio printing “unhandled task exception” tracebacks before task done-callbacks run, by catching DisconnectedError inside the create_task() wrapper rather than inside each streaming coroutine.

Changes:

  • Wrap all create_task() coroutines with _wrap_disconnected() to swallow DisconnectedError before it escapes the coroutine.
  • Remove now-redundant per-coroutine except DisconnectedError: pass blocks from streaming loops.
  • Remove the dead DisconnectedError handling branch from _task_done_callback().

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/cfclient/gui.py Adds coroutine wrapper to swallow DisconnectedError before QtAsyncio can log it; simplifies done-callback handling.
src/cfclient/ui/tabs/FlightTab.py Removes redundant DisconnectedError swallowing from motor-streaming loop.
src/cfclient/ui/pose_logger.py Removes redundant DisconnectedError swallowing from pose-streaming loop.
src/cfclient/ui/main.py Removes redundant DisconnectedError swallowing from battery-streaming loop.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/cfclient/gui.py
Comment thread src/cfclient/gui.py Outdated
Comment thread src/cfclient/gui.py
gemenerik added 2 commits May 6, 2026 11:36
Makes it possible to identify which task was interrupted when multiple
background tasks are torn down by a single disconnect.
DisconnectedError is intentionally swallowed by the wrapper as a normal
shutdown case; the original docstring suggested all exceptions propagate.
Copy link
Copy Markdown
Member

@ArisMorgens ArisMorgens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants