textual icon indicating copy to clipboard operation
textual copied to clipboard

Unclosed event loop with easing example

Open sanders41 opened this issue 3 years ago • 11 comments

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

sanders41 avatar Oct 01 '21 01:10 sanders41

Interesting. I don't see that, probably because I develop with 3.7. Shutting down cleanly is one of the hardest things about asyncio.

willmcgugan avatar Oct 01 '21 08:10 willmcgugan

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.

sanders41 avatar Oct 01 '21 12:10 sanders41

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.

willmcgugan avatar Oct 01 '21 12:10 willmcgugan

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?

sanders41 avatar Oct 01 '21 12:10 sanders41

Try uninstalling textual first, but I would have thought that would be enough.

So you are seeing this on Linux consistently, but MacOS intermittently?

willmcgugan avatar Oct 01 '21 12:10 willmcgugan

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.

sanders41 avatar Oct 01 '21 12:10 sanders41

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.

lllama avatar Oct 01 '21 20:10 lllama

Screenshot 2022-01-07 at 21 39 49

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 ""))

pom11 avatar Jan 07 '22 19:01 pom11

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 when uvloop is installed. Screenshot from 2022-05-04 10-55-21

  • 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:

olivierphi avatar May 04 '22 09:05 olivierphi

@DrBenton There is an open PR above for this ^ Although I thought this wasn't an issue on the css branch

darrenburns avatar May 04 '22 12:05 darrenburns

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:

olivierphi avatar May 11 '22 10:05 olivierphi

https://github.com/Textualize/textual/wiki/Sorry-we-closed-your-issue

willmcgugan avatar Oct 25 '22 09:10 willmcgugan

Did we solve your problem?

Consider buying the Textualize developers a coffee to say thanks.

Textualize

github-actions[bot] avatar Oct 25 '22 09:10 github-actions[bot]