Skip to content
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

active_message_pump.get() results in LookupError #2301

Closed
davep opened this issue Apr 17, 2023 · 1 comment · Fixed by #2302
Closed

active_message_pump.get() results in LookupError #2301

davep opened this issue Apr 17, 2023 · 1 comment · Fixed by #2302
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented Apr 17, 2023

It seems that active_message_pump.get, when called inside an event handler or action, results in a LookupError exception. For example:

from textual.app        import App, ComposeResult
from textual.binding    import Binding
from textual.containers import Center
from textual.widgets    import Header, Footer, Button, Label
from textual._context   import active_message_pump

class MsgPumpApp( App[ None ] ):

    CSS = """
    Screen {
        align: center middle;
    }
    """

    BINDINGS = [
        Binding( "space", "show_pump", "Show Message Pump Within Action" ),
    ]

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Center( Button( "Show Message Pump Within Message" ) )
        yield Center( Label( "Active Message Pump Will Be Reported Here" ) )
        yield Footer()

    def on_button_pressed( self ) -> None:
        self.query_one( Label ).update( f"{active_message_pump.get()!r}")

    def action_show_pump( self ) -> None:
        self.query_one( Label ).update( f"{active_message_pump.get()!r}")

if __name__ == "__main__":
    MsgPumpApp().run()

If the button is pressed, or Space is pressed, results in the likes of:

LookupError: <ContextVar name='active_message_pump' at 0x105089080>
@github-actions
Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant