mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix for active message pump (#2148)
* fix for active message pump * Add log file * changelog
This commit is contained in:
@@ -35,6 +35,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Added auto_scroll attribute to TextLog https://github.com/Textualize/textual/pull/2127
|
||||
- Added scroll_end switch to TextLog.write https://github.com/Textualize/textual/pull/2127
|
||||
- Added Screen.ModalScreen which prevents App from handling bindings. https://github.com/Textualize/textual/pull/2139
|
||||
- Added TEXTUAL_LOG env var which should be a path that Textual will write verbose logs to (textual devtools is generally preferred) https://github.com/Textualize/textual/pull/2148
|
||||
|
||||
|
||||
## [0.16.0] - 2023-03-22
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Callable
|
||||
import rich.repr
|
||||
from rich.console import RenderableType
|
||||
|
||||
from . import constants
|
||||
from ._context import active_app
|
||||
from ._log import LogGroup, LogVerbosity
|
||||
|
||||
@@ -61,6 +62,16 @@ class Logger:
|
||||
print_args = (*args, *[f"{key}={value!r}" for key, value in kwargs.items()])
|
||||
print(*print_args)
|
||||
return
|
||||
if constants.LOG_FILE:
|
||||
output = " ".join(str(arg) for arg in args)
|
||||
if kwargs:
|
||||
key_values = " ".join(
|
||||
f"{key}={value!r}" for key, value in kwargs.items()
|
||||
)
|
||||
output = f"{output} {key_values}" if output else key_values
|
||||
|
||||
with open(constants.LOG_FILE, "a") as log_file:
|
||||
print(output, file=log_file)
|
||||
if app.devtools is None or not app.devtools.is_connected:
|
||||
return
|
||||
|
||||
|
||||
@@ -34,3 +34,6 @@ BORDERS = list(BORDER_CHARS)
|
||||
DEBUG: Final[bool] = get_environ_bool("TEXTUAL_DEBUG")
|
||||
|
||||
DRIVER: Final[str | None] = get_environ("TEXTUAL_DRIVER", None)
|
||||
|
||||
LOG_FILE: Final[str | None] = get_environ("TEXTUAL_LOG", None)
|
||||
"""A last resort log file that appends all logs, when devtools isn't working."""
|
||||
|
||||
@@ -399,7 +399,6 @@ class MessagePump(metaclass=MessagePumpMeta):
|
||||
def _start_messages(self) -> None:
|
||||
"""Start messages task."""
|
||||
if self.app._running:
|
||||
active_message_pump.set(self)
|
||||
self._task = create_task(
|
||||
self._process_messages(), name=f"message pump {self}"
|
||||
)
|
||||
@@ -409,6 +408,7 @@ class MessagePump(metaclass=MessagePumpMeta):
|
||||
|
||||
async def _process_messages(self) -> None:
|
||||
self._running = True
|
||||
active_message_pump.set(self)
|
||||
|
||||
await self._pre_process()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user