How to debug in Plone 5.2.x with ipdb?

Dear community,

I found this recurrent warning:

/home/.pyenv/versions/3.8.8/lib/python3.8/asyncio/ 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

when I was trying to debug some python code introducing an ipdb in Plone 5.2.5, I found the next solution to avoid this:

import warnings
warnings.filterwarnings(action="ignore", message="unclosed", category=ResourceWarning)
import ipdb; ipdb.set_trace()

but I'm not sure if it's the best option to solve this type of warning.
Are there other options to debug Plone better than ipdb?

Thank you for your answers!

ResourceWarnings flag cases when you might (unnecessarily) block a valuable resource for a long time. If you see the ResourceWarning, then actually the resource in no longer blocked.

Let's look at an example: open(...).write(..) will issue a ResourceWarning (when the file object is garbage collected) because the file has not been closed explicitly. With CPython, there is not a real problem because its reference count based garbage collection will delete (and implicitly close) the file immediately after the write. With other Python implementations (not using reference counts) it may take a long time before the file object is garbage collected and until then the rare resource "file descriptor" associated with the file object is blocked.

Even with CPython, resources may be blocked for a long time should the object be involved in a reference cycle (because for them, reference counting is ineffective). But if your application does not create reference cycles routinely, the risk is not too great.

For my point of view, you can ignore ResourceWarnings unless you either observe real resource problems or you get ResourceWarnings from code under your own control. In the latter case, you likely should follow "explicit is better than implicit" and release the resource explicitly.

Ok Dieter, I will ignore this warning because I don't have resource problems. Thank you very much for your explanation.

Being it asyncio, if you're debugging, time will pass and some asyncio timeout will be hit. Code usually run with the assumption that it will run in a short time, which doesn't happen during debug sessions.

1 Like


I'm not sure if it's related, I think it is, but on my dev systems I end up manually editing wsgi.ini and setting threads to 1 - or else my debugging goes a bit haywire.

But maybe that's a completely different topic. Nevermind.

Plone Foundation Code of Conduct