Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions changes/3342.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
An incompatibility with Textual 3.0 that caused log messages to be generated on the console on app exist has been resolved.
Comment thread
mhsmith marked this conversation as resolved.
Outdated
2 changes: 1 addition & 1 deletion textual/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ root = ".."

[tool.setuptools_dynamic_dependencies]
dependencies = [
"textual >= 0.44.0",
"textual >= 3.0.0, < 4.0.0",
"toga-core == {version}",
]

Expand Down
18 changes: 17 additions & 1 deletion textual/src/toga_textual/app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import threading

import toga
from textual.app import App as TextualApp
Expand Down Expand Up @@ -27,6 +28,7 @@ def __init__(self, interface):
self.interface._impl = self

self.loop = asyncio.new_event_loop()
asyncio.set_event_loop(self.loop)
self.native = TogaApp(self)

self._current_window = None
Expand Down Expand Up @@ -56,7 +58,21 @@ def exit(self):
self.native.exit()

def main_loop(self):
self.loop.run_until_complete(self.native.run_async(headless=self.headless))
# This is duplicating the bulk of TextualApp.run(); however, that entry point
# doesn't give any control over the event loop that is used. The key detail
# is that the _context() is required to capture logging messages generated
# as the app is shutting down. See textualize/textual#5091.
with self.native._context():
try:
self.native._loop = self.loop
self.native._thread_id = threading.get_ident()

self.loop.run_until_complete(
self.native.run_async(headless=self.headless)
)
finally:
self.native._loop = None
self.native._thread_id = 0

def set_icon(self, icon):
pass
Expand Down