Skip to content

Commit 0c81c0d

Browse files
DenubisBrian Ballsun-StantonclaudefalkoschindlerBrian Ballsun-Stanton
authored
Wake outbox loop on stop() to avoid ~1s shutdown delay (#5805)
### Motivation `Outbox.stop()` sets `_should_stop` but doesn't wake the loop when it is sleeping in `Event.wait(timeout=1.0)`. The loop only checks `_should_stop` at the top of the while loop, so after `stop()` is called the outbox loop lingers for up to 1 second until the `Event.wait` times out. This is a resource hygiene issue: deleted clients' outbox loops should stop promptly rather than lingering. The linger is concurrent (nothing awaits the outbox task after `stop()`), so it does not block the caller. But it leaves unnecessary background tasks in the event loop and extends the cleanup window that test harnesses or diagnostic tooling must account for. Closes #5804 ### Implementation `Outbox.stop()` now calls `self._set_enqueue_event()` after setting `_should_stop = True`. This is the same helper already used by `enqueue_update()`, `enqueue_delete()`, `enqueue_message()`, and `try_rewind()` to wake the loop — so the fix follows the existing pattern rather than introducing anything new. The loop wakes, sees `_should_stop` is true, and exits immediately. ### Progress - [X] I chose a meaningful title that completes the sentence: "If applied, this PR will..." - [X] The implementation is complete. - [X] If this PR addresses a security issue, it has been coordinated via the [security advisory](https://github.com/zauberzeug/nicegui/security/advisories/new) process. - [X] Pytests have been added (or are not necessary). - [X] Documentation has been added (or is not necessary). --------- Co-authored-by: Brian Ballsun-Stanton <denubisx@noreply.github.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Falko Schindler <falko@zauberzeug.com> Co-authored-by: Brian Ballsun-Stanton <denubis@noreply.github.com>
1 parent 2534a08 commit 0c81c0d

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

nicegui/outbox.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,4 @@ def prune_history(self, next_message_id: MessageId) -> None:
183183
def stop(self) -> None:
184184
"""Stop the outbox loop."""
185185
self._should_stop = True
186+
self._set_enqueue_event() # wake the loop so it checks _should_stop immediately

0 commit comments

Comments
 (0)