Name 'ResourceWarning' is not defined

While using a 3rd party library, I did get an error:

Exception ignored in: <function Popen.__del__ at 0x7ff40da83ca0>
Traceback (most recent call last):
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/subprocess.py", line 947, in __del__
NameError: name 'ResourceWarning' is not defined
Exception ignored in: <function Popen.__del__ at 0x7ff40da83ca0>
Traceback (most recent call last):
  File "/opt/rh/rh-python38/root/usr/lib64/python3.8/subprocess.py", line 947, in __del__
NameError: name 'ResourceWarning' is not defined
Stopping com.raytheon.uf.viz.core plugin
2023-05-24 22:05:42 VizApplication's runtime shutdown hook triggered

In the method Pipe.__del__there is a comment

if self.returncode is None:
    # Not reading subprocess exit status creates a zombie process which
    # is only destroyed at the parent python process exit
        _warn("subprocess %s is still running" % self.pid,
              ResourceWarning, source=self)

I can understand that there is a bug somewhere in library (which is Java and Python with Jep as a glue) which causes self.returncode to be not None. What puzzles me is why a builtin ResourceWarning class disappears.

$ python
Python 3.8.14 (default, Sep 19 2022, 09:47:48)
[GCC 9.1.1 20190605 (Red Hat 9.1.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> ResourceWarning
<class 'ResourceWarning'>
>>> 

Any ideas what is going on?

This looks like one of the quirky things that can happen when __del__ methods run during various stages of interpreter shutdown. Can you reproduce this problem on a more recent version of Python?

Not easily. It is a huge system: https://www.weather.gov/cp/DownloadAWIPS. It is not a critical issue, I’ll poke around and see whether this is a random occurrence. My guess is that Jep is the culprit.

Oh well. The other way of looking at it is: If this is just an error on shutdown, it’s not a major problem. There’s a good chance it’s been fixed in a newer version of Python, but until you can upgrade, most likely you’ll have this noisy message as it shuts down.

As to the actual reason for self.returncode to be None though… that suggests that it’s looking at a subprocess that hasn’t terminated, so you may need to look into whether or not that’s a problem.