Isn't TypeError built in?

Chris Angelico rosuav at gmail.com
Sun Dec 12 20:42:24 EST 2021


On Mon, Dec 13, 2021 at 12:31 PM Mike Dewhirst via Python-list
<python-list at python.org> wrote:
>
> Obviously something is wrong elsewhere but I'm not sure where to look.
> Ubuntu 20.04 with plenty of RAM.
>
>      def __del__(self):
>          try:
>              for context_obj in self._context_refs:
>                  try:
>                      delattr(context_obj, self._attr_name)
>                  except AttributeError:
>                      pass
>
>          except TypeError:        # THIS IS LINE 96 IN THE APACHE2 ERROR
> LOG BELOW
>
>              # WeakSet.__iter__ can crash when interpreter is shutting
> down due
>              # to _IterationGuard being None.
>              pass
>
> [Mon Dec 13 01:15:49.875993 2021] [mpm_event:notice] [pid 1033:tid
> 140446449658944] AH00493: SIGUSR1 received.  Doing graceful restart
> [Mon Dec 13 01:15:49.878443 2021] [so:warn] [pid 1033] AH01574: module
> dav_module is already loaded, skipping
> [Mon Dec 13 01:15:49.885659 2021] [mpm_event:notice] [pid 1033:tid
> 140446449658944] AH00489: Apache/2.4.41 (Ubuntu) SVN/1.13.0
> OpenSSL/1.1.1f mod_wsgi/4.6.8 Python/3.8 configured -- resuming normal
> operations
> [Mon Dec 13 01:15:49.885664 2021] [core:notice] [pid 1033:tid
> 140446449658944] AH00094: Command line: '/usr/sbin/apache2'
> Exception ignored in: <function Local.__del__ at 0x7fbc380964c0>
> Traceback (most recent call last):
>    File "/usr/local/lib/python3.8/dist-packages/asgiref/local.py", line
> 96, in __del__
> NameError: name 'TypeError' is not defined
> Exception ignored in: <function Local.__del__ at 0x7fbc380964c0>
> Traceback (most recent call last):
>    File "/usr/local/lib/python3.8/dist-packages/asgiref/local.py", line
> 96, in __del__
> NameError: name 'TypeError' is not defined
>
> Any hints welcome ...

During interpreter shutdown, all kinds of things can go weird. The
order that things get destroyed isn't always clearly defined.

Is it possible to do the cleanup work before interpreter shutdown?
Alternatively: maybe take a local reference to the exception types you
need to refer to (just "AttributeError = AttributeError" at top level
should do it), which should keep them alive longer (I think). Worst
case, capture *all* exceptions, then look at e.__class__.__name__ and
match on that.

ChrisA


More information about the Python-list mailing list