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

Switching to v0.1.11 Caused a Crash #101

Closed
JosephTLyons opened this issue Sep 13, 2021 · 3 comments
Closed

Switching to v0.1.11 Caused a Crash #101

JosephTLyons opened this issue Sep 13, 2021 · 3 comments

Comments

@JosephTLyons
Copy link

JosephTLyons commented Sep 13, 2021

I upgraded to v0.1.11 and trying to run an app using v0.1.10 immediately crashed (no other changes were introduced, just the version bump:

❯ python main.py
Traceback (most recent call last):
  File "/Users/josephlyons/Programming/Python/termifind/main.py", line 34, in <module>
    main()
  File "/Users/josephlyons/Programming/Python/termifind/main.py", line 30, in main
    TermiFindApplication.run(log="termifind.log")
  File "/Users/josephlyons/Programming/Python/termifind/virtual_environment/lib/python3.10/site-packages/textual/app.py", line 187, in run
    asyncio.run(run_app())
  File "/Users/josephlyons/.pyenv/versions/3.10.0b3/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/Users/josephlyons/.pyenv/versions/3.10.0b3/lib/python3.10/asyncio/base_events.py", line 641, in run_until_complete
    return future.result()
  File "/Users/josephlyons/Programming/Python/termifind/virtual_environment/lib/python3.10/site-packages/textual/app.py", line 184, in run_app
    app = cls(console=console, screen=screen, driver_class=driver, **kwargs)
  File "/Users/josephlyons/Programming/Python/termifind/main.py", line 14, in __init__
    self.ui: UI = UI(self.path_container)
  File "/Users/josephlyons/Programming/Python/termifind/src/ui/ui.py", line 22, in __init__
    self.previous_directory_container_scroll_view: TermiFindScrollView = self.__get_scroll_view(
  File "/Users/josephlyons/Programming/Python/termifind/src/ui/ui.py", line 38, in __get_scroll_view
    item_buttons_view: TermiFindButtonsView = self.__get_item_buttons_view(directory_container, should_style_text)
  File "/Users/josephlyons/Programming/Python/termifind/src/ui/ui.py", line 66, in __get_item_buttons_view
    termifind_buttons_view.add(TermiFindButton(item_name_text))
  File "/Users/josephlyons/Programming/Python/termifind/src/ui/custom_views.py", line 10, in add
    self.layout.add(button)
  File "/Users/josephlyons/Programming/Python/termifind/virtual_environment/lib/python3.10/site-packages/textual/layouts/vertical.py", line 27, in add
    self._max_widget_width = max(widget.app.measure(widget), self._max_widget_width)
  File "/Users/josephlyons/Programming/Python/termifind/virtual_environment/lib/python3.10/site-packages/textual/message_pump.py", line 58, in app
    return active_app.get()
LookupError: <ContextVar name='active_app' at 0x1031a4f90>
sys:1: ResourceWarning: unclosed file <_io.TextIOWrapper name='termifind.log' mode='wt' encoding='UTF-8'>

I will try to post a minimal working piece of code that causes the crash, just wanted to get this logged before I forgot about it.

Repo & Branch I'm working on is here: https://github.com/JosephTLyons/termifind-python/tree/Continue-Adapting-Code-To-Use-Textual

@willmcgugan
Copy link
Collaborator

I think I see the problem. You may be constructing widgets or views from the App constructor, prior to the asyncio context running. This may have worked in a previous version, but you will need to create widgets in a handler, on_mount is the best place for that.

@JosephTLyons
Copy link
Author

That solved the original issue here. I have a few other issues that have come up, but I will close this one and open new issues if I can't solve it on my own. Thank you.

@github-actions
Copy link

Did I solve your problem?

Consider sponsoring my work on Textual with a monthly donation.

Or buy me a coffee to say thanks.

Will McGugan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants