textual
textual copied to clipboard
Unclosed event loop with easing example
Every time I close the easing example. I get the following error:
/usr/lib/python3.9/asyncio/base_events.py:681: ResourceWarning: unclosed event loop <_UnixSelectorEventLoop running=False closed=False debug=False>
_warn(f"unclosed event loop {self!r}", ResourceWarning, source=self)
ResourceWarning: Enable tracemalloc to get the object allocation traceback
I am thinking there are still messages processing at shutdown that are keeping the loop running, but I have not been able to track down the root cause yet.
Possibly a similar issue to #82?
OS: Manjaro Linux 21.1.4
Interesting. I don't see that, probably because I develop with 3.7. Shutting down cleanly is one of the hardest things about asyncio.
I tested 3.7 and am seeing the error there also. I tried it out on my Mac, and there it seems to be random. Sometimes I get the error and sometimes I don't with 3.7, 3.8, and 3.9.
Are you certain you are running the latest code? What does pip freeze | grep textual
give you?
It has very possibly reoccured, but I had fixed a very similar issue a while back.
I'm running from my fork. I tried pull upstream and then a fresh poetry install
, but am still seeing the error. Do I need to do a separate install to run the examples?
Try uninstalling textual first, but I would have thought that would be enough.
So you are seeing this on Linux consistently, but MacOS intermittently?
I tried deleting poetry's virtual environment and re-creating it, but no difference.
Correct, I am getting the error every time on Linux, but only intermittently on MacOS. I'll keep doing some testing to see if I can get any more information.
Not that I know what I'm talking about but there was a good talk at EuroPython a few years ago that talked about asyncio things, including shutting down gracefully.

i get the same error when trying to get docker container status. along the dumped data i can see the widgets rendered.
- textual 0.1.13
- docker 5.0.3
- python 3.8.10
class Container(Widget):
mouse_over = Reactive(False)
def __init__(self, id: str = None):
super().__init__(id=id)
self.id = id
def container(self):
try:
client = docker.from_env()
container = client.containers.get(self.id)
status = container.status()
client.close()
return status
except Exception as e:
return "Error"
def on_mount(self):
self.set_interval(1, self.refresh)
def render(self):
data = self.container()
return Panel(data, style=("on red" if self.mouse_over else ""))
I can indeed reproduce the bug (on Ubuntu).
-
Python 3.8.13: the
asyncio/base_events.py:686: ResourceWarning: unclosed event loop
error is displayed in the background of the Textual display, when the easing example is launched - :warning: however it doesn't happen whenuvloop
is installed. -
Python 3.9.12: it is displayed when we exit the app with Ctrl+C - :warning: however it doesn't happen when
uvloop
is installed.
I'm going to take a look at this! :slightly_smiling_face:
@DrBenton There is an open PR above for this ^ Although I thought this wasn't an issue on the css
branch
Status update: the bug seems to be fixed on the css
branch, where the current Textual development is taking place. So hopefully it will no longer be visible when this branch will be merged to main
:slightly_smiling_face: :crossed_fingers:
https://github.com/Textualize/textual/wiki/Sorry-we-closed-your-issue