Skip to content

Expose a cancellable route watch API in Python #3193

Description

@kixelated

Problem

Python handles route changes differently from the other bindings. BroadcastConsumer.route_changed() lazily creates a route watch, caches it in a private field, and awaits its next value:

The watch handle is not public and has no deterministic cancellation path. A caller that abandons route observation must rely on garbage collection or broadcast shutdown to release the native watch.

Other wrappers expose explicit lifetime ownership:

Proposed direction

Expose a public Python route watch abstraction with deterministic cleanup, following the existing wrapper conventions. Suitable shapes include:

  • an async iterator returned by routes()
  • an async context-managed RouteWatch
  • both, with route_changed() retained only as a convenience over the owned watch

The owner should be able to cancel a pending wait and release the native resource without waiting for garbage collection.

Acceptance criteria

  • Python callers can explicitly own and close a route watch.
  • Abandoning iteration deterministically cancels the native watch.
  • A pending route wait is cancellable by normal asyncio task cancellation.
  • Tests cover early iterator exit and cancellation while waiting.
  • Lifecycle documentation matches the Go, Swift, and Kotlin ownership contract.

(Written by GPT-5.6)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions