You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"TypeError: 'NoneType' object is not callable" during calls to wasmtime.Managed.__del__ #302
Python 3.14.0 (main, Oct 14 2025, 21:10:22) [Clang 20.1.4 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import wasmtime, wasmtime.loader
...
... import loader_component_add # type:ignore
...
...
... store = wasmtime.Store()
... component = loader_component_add.Root(store)
... assert component.add(store, 1, 2) ==3
...
>>>
Exception ignored while calling deallocator <function Managed.__del__ at 0x102961170>:
Traceback (most recent call last):
File "/Users/alex/src/wasmtime-py/.venv/lib/python3.14/site-packages/wasmtime/_managed.py", line 95, in __del__
File "/Users/alex/src/wasmtime-py/.venv/lib/python3.14/site-packages/wasmtime/_managed.py", line 44, in close
File "/Users/alex/src/wasmtime-py/.venv/lib/python3.14/site-packages/wasmtime/_store.py", line 31, in _delete
TypeError: 'NoneType' object is not callable
Exception ignored while calling deallocator <function Managed.__del__ at 0x102961170>:
Traceback (most recent call last):
File "/Users/alex/src/wasmtime-py/.venv/lib/python3.14/site-packages/wasmtime/_managed.py", line 95, in __del__
File "/Users/alex/src/wasmtime-py/.venv/lib/python3.14/site-packages/wasmtime/_managed.py", line 44, in close
File "/Users/alex/src/wasmtime-py/.venv/lib/python3.14/site-packages/wasmtime/_engine.py", line 19, in _delete
TypeError: 'NoneType' object is not callable
The exception does not occur when the example is run as a script
changed the title [-]"TypeError: 'NoneType' object is not callable" in wasmtime.Mananged.__del__[/-][+]"TypeError: 'NoneType' object is not callable" during calls to wasmtime.Managed.__del__[/+]on Oct 27, 2025
➜ examples git:(nox) .venv/bin/python Python 3.13.7 (main, Aug 18 2025, 19:02:43) [Clang 20.1.4 ] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import wasmtime, wasmtime.loader>>> import loader_component_add>>> store = wasmtime.Store()>>> Exception ignored in: <function Managed.__del__ at 0x1035b8a40>Traceback (most recent call last): File "/Users/alex/src/wasmtime-py/examples/.venv/lib/python3.13/site-packages/wasmtime/_managed.py", line 95, in __del__ File "/Users/alex/src/wasmtime-py/examples/.venv/lib/python3.13/site-packages/wasmtime/_managed.py", line 44, in close File "/Users/alex/src/wasmtime-py/examples/.venv/lib/python3.13/site-packages/wasmtime/_store.py", line 31, in _deleteTypeError: 'NoneType' object is not callableException ignored in: <function Managed.__del__ at 0x1035b8a40>Traceback (most recent call last): File "/Users/alex/src/wasmtime-py/examples/.venv/lib/python3.13/site-packages/wasmtime/_managed.py", line 95, in __del__ File "/Users/alex/src/wasmtime-py/examples/.venv/lib/python3.13/site-packages/wasmtime/_managed.py", line 44, in close File "/Users/alex/src/wasmtime-py/examples/.venv/lib/python3.13/site-packages/wasmtime/_engine.py", line 19, in _deleteTypeError: 'NoneType' object is not callable
This might be due to something happening during process shutdown? As python variables are thrown away the store the loader uses gets disposed of but I guess the dll has already been unloaded which prevents destroying the store?
I'm not sure if there's a way to force the modules to get destroyed in a different way or something like that. Or maybe register some sort of shutdown hook?
I'm still reading up and pondering. In general using __del__() is discouraged, first order advice is don't use it; use other mechanisms instead (e.g. __enter__()/__exit__(), weakref.finalize()).
Yeah this one's a bit tough. I don't believe that __del__ can be removed as it's used here as a last-ditch attempt to cleanup resources. The test suite would probably pass if they were all deleted, but that would also mean that quite a lot of memory is leaked. All managed objects already support __enter__ and explicit close method calls, so it's possible to explicitly and manually manage memory but __del__ can't be deleted as that's not always required to be called.
I think the main issue here is that there's a global which has wasm which is being deleted during process teardown. One option might be to, for that specific object, remove its destructor. That might be a specific override perhaps? But basically the loader's global store could be configured to never get dropped
My conclusion on this is that this is unfixable personally. I'd be ok deleting the loader module as while it's kind of "cute" to import a module I feel like this is an example where it's too magic.
Activity
moreati commentedon Oct 27, 2025
The problem may be specific to Python >= 3.13. I could not reproduce it with 3.9 - 3.12 (as builkt for
uvon macOS)Details
[-]"TypeError: 'NoneType' object is not callable" in wasmtime.Mananged.__del__[/-][+]"TypeError: 'NoneType' object is not callable" during calls to wasmtime.Managed.__del__[/+]moreati commentedon Oct 27, 2025
Smallest reproducer so far
Details
alexcrichton commentedon Oct 27, 2025
This might be due to something happening during process shutdown? As python variables are thrown away the store the loader uses gets disposed of but I guess the dll has already been unloaded which prevents destroying the store?
I'm not sure if there's a way to force the modules to get destroyed in a different way or something like that. Or maybe register some sort of shutdown hook?
moreati commentedon Oct 28, 2025
I'm still reading up and pondering. In general using
__del__()is discouraged, first order advice is don't use it; use other mechanisms instead (e.g.__enter__()/__exit__(),weakref.finalize()).CPython docs have a list of warnings, PyPy documents further intricacies/differences.
Open questions in my head
__del__()as a load bearing part of shutdown/cleanup vs a just-in-case safety net for abnormal cases?Avenues of investigation (non exhaustive, not mutually exclusive)
__del__()s and see how much of the test suite passes__del__()s, perhaps opt-in (e.g. enabled in CI). The subprocess module does this, which helped me identify/fix file descriptor leaks in https://github.com/mitogen-hq/mitogen.moreati commentedon Oct 28, 2025
Providing FFI callacbles to
__del__()implementations (73e7f44) didn't eliminate the TypeErrors.Providing FFI callacbles to
_delete()implementations (4475354) did.I'm not proposing these commits as fixes, they're just investigation results.
alexcrichton commentedon Oct 29, 2025
Yeah this one's a bit tough. I don't believe that
__del__can be removed as it's used here as a last-ditch attempt to cleanup resources. The test suite would probably pass if they were all deleted, but that would also mean that quite a lot of memory is leaked. All managed objects already support__enter__and explicitclosemethod calls, so it's possible to explicitly and manually manage memory but__del__can't be deleted as that's not always required to be called.I think the main issue here is that there's a global which has wasm which is being deleted during process teardown. One option might be to, for that specific object, remove its destructor. That might be a specific override perhaps? But basically the loader's global store could be configured to never get dropped
alexcrichton commentedon Nov 1, 2025
My conclusion on this is that this is unfixable personally. I'd be ok deleting the
loadermodule as while it's kind of "cute" to import a module I feel like this is an example where it's too magic.moreati commentedon Nov 1, 2025
Delete `wasmtime.loader` and `wasmtime.bindgen`
Delete `wasmtime.loader` and `wasmtime.bindgen` (#310)