-
Notifications
You must be signed in to change notification settings - Fork 837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot find "active_app" #5421
Comments
This snippet triggers the error: import asyncio
from textual.app import App, ComposeResult
from textual.containers import Container
from textual.widgets import MarkdownViewer
EXAMPLE_MARKDOWN = """\
# Markdown Viewer
This is an example of Textual's `MarkdownViewer` widget.
## Features
Markdown syntax and extensions are supported.
- Typography *emphasis*, **strong**, `inline code` etc.
- Headers
- Lists (bullet and ordered)
- Syntax highlighted code blocks
- Tables!
## Tables
Tables are displayed in a DataTable widget.
| Name | Type | Default | Description |
| --------------- | ------ | ------- | ---------------------------------- |
| `show_header` | `bool` | `True` | Show the table header |
| `fixed_rows` | `int` | `0` | Number of fixed rows |
| `fixed_columns` | `int` | `0` | Number of fixed columns |
| `zebra_stripes` | `bool` | `False` | Display alternating colors on rows |
| `header_height` | `int` | `1` | Height of header row |
| `show_cursor` | `bool` | `True` | Show a cell cursor |
"""
class MyApp(App):
def compose(self) -> ComposeResult:
self.container = Container()
yield self.container
async def task(app: MyApp):
await asyncio.sleep(1)
app.container.mount(MarkdownViewer(EXAMPLE_MARKDOWN))
async def main():
app = MyApp()
t0 = asyncio.create_task(task(app))
t1 = asyncio.create_task(app.run_async())
await asyncio.Future()
if __name__ == "__main__":
asyncio.run(main()) |
Note that it works fine if I replace |
One workaround is to: from textual._context import active_app And to set the active app before mounting the widget: active_app.set(app)
app.container.mount(MarkdownViewer(EXAMPLE_MARKDOWN)) But I'm not sure if there's a better solution? |
I wouldn't expect the MRE to work. It looks like it would call Not sure if that explains your original issue. Could you be creating a timer before the app is running? |
The |
I am running into this problem when calling For context, I am running into it here basnijholt/tuitorial#18 |
While running a Textual app with its
run_async()
method, I get this message in the Textual console:Sometimes it makes the app crash, sometimes not.
I don't have a reproducible example because it happens in a bigger application, but do you know what could cause this?
If you don't have the
textual
command on your path, you may have forgotten to install thetextual-dev
package.Feel free to add screenshots and / or videos. These can be very helpful!
The text was updated successfully, but these errors were encountered: