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
2 changes: 1 addition & 1 deletion src/formbridge/bridge/in_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ def __init__(
def close(self) -> None:
"""Fence callbacks queued by this bridge instance."""

self._dispatcher.close()
self._dispatcher.close_dispatch()

def register_provider(self, provider: UiCodeDocumentProviderABC) -> None:
self._registry.register_code_document_provider(provider)
Expand Down
13 changes: 10 additions & 3 deletions src/formbridge/services/main_thread_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ def _complete(self) -> None:


class MainThreadDispatcher(ABC):
"""Own every callable queued onto the owner thread."""
"""Own every callable queued onto the owner thread.

def __init__(self) -> None:
A capability as well as an object: a toolkit's application widget can inherit its
member beside the widget base (the constructor continues the cooperative chain), so
posting work onto its thread is the application's own method, not a forward to a
helper. Its shutdown is ``close_dispatch``, named apart from the widget's ``close``.
"""

def __init__(self, *args: object, **kwargs: object) -> None:
super().__init__(*args, **kwargs)
self._lock = threading.Lock()
self._closed = False
self._calls: set[DispatchedCall] = set()
Expand All @@ -110,7 +117,7 @@ def _deliver(self, call: DispatchedCall) -> None:
def _undeliverable_error(self) -> MainThreadDispatchError:
return MainThreadDispatchError("No owner thread is available for dispatch.")

def close(self) -> None:
def close_dispatch(self) -> None:
"""Reject new work and cancel callbacks which have not begun."""

with self._lock:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_main_thread_dispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_close_cancels_posted_work_and_rejects_new_work() -> None:
dispatcher = QueuedMainThreadDispatcher()
calls: list[str] = []
dispatcher.post(lambda: calls.append("late"))
dispatcher.close()
dispatcher.close_dispatch()
finished: Future[None] = Future()
finished.set_result(None)
dispatcher.run_until(finished)
Expand Down
Loading