Skip to content

Commit c2f0771

Browse files
authored
Fix CancelledError (#2895)
* Rodrigo's test * changelog * comment oddity
1 parent a35e92b commit c2f0771

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## Unreleased
9+
10+
### Fixed
11+
12+
- Fixed CancelledError issue with timer https://github.com/Textualize/textual/issues/2854
13+
14+
815
## [0.29.0] - 2023-07-03
916

1017
### Changed
@@ -23,6 +30,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
2330
- Fixed crash when columns were added to populated `DataTable` https://github.com/Textualize/textual/pull/2836
2431
- Fixed issues with opacity on Screens https://github.com/Textualize/textual/issues/2616
2532
- Fixed style problem with selected selections in a non-focused selection list https://github.com/Textualize/textual/issues/2768
33+
- Fixed sys.stdout and sys.stderr being None https://github.com/Textualize/textual/issues/2879
2634

2735
## [0.28.1] - 2023-06-20
2836

src/textual/timer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ async def _tick(self, *, next_timer: float, count: int) -> None:
148148
if self._callback is not None:
149149
try:
150150
await invoke(self._callback)
151+
except CancelledError:
152+
# https://github.com/Textualize/textual/pull/2895
153+
# Re-raise CancelledErrors that would be caught by the following exception block in Python 3.7
154+
raise
151155
except Exception as error:
152156
app = active_app.get()
153157
app._handle_exception(error)

tests/test_await_remove.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from textual.app import App
2+
from textual.widgets import Label
3+
4+
5+
class SelfRemovingLabel(Label):
6+
def on_mount(self) -> None:
7+
self.set_timer(0.2, self.remove)
8+
9+
10+
class RemoveOnTimerApp(App[None]):
11+
def on_mount(self):
12+
for _ in range(5):
13+
self.mount(SelfRemovingLabel("I will remove myself!"))
14+
15+
16+
async def test_multiple_simultaneous_removals():
17+
"""Regression test for https://github.com/Textualize/textual/issues/2854."""
18+
# The app should run and finish without raising any errors.
19+
async with RemoveOnTimerApp().run_test() as pilot:
20+
await pilot.pause(0.3)
21+
# Sanity check to ensure labels were removed.
22+
assert len(pilot.app.query(Label)) == 0

0 commit comments

Comments
 (0)