[pypy-svn] r50455 - pypy/dist/pypy/translator/c
cfbolz at codespeak.net
cfbolz at codespeak.net
Wed Jan 9 14:19:42 CET 2008
Author: cfbolz
Date: Wed Jan 9 14:19:41 2008
New Revision: 50455
Modified:
pypy/dist/pypy/translator/c/genc.py
Log:
a best-effort solution to cleaning up the shared libraries that genc loads
Modified: pypy/dist/pypy/translator/c/genc.py
==============================================================================
--- pypy/dist/pypy/translator/c/genc.py (original)
+++ pypy/dist/pypy/translator/c/genc.py Wed Jan 9 14:19:41 2008
@@ -161,6 +161,30 @@
return db
+class ModuleWithCleanup(object):
+ def __init__(self, mod):
+ self.__dict__['mod'] = mod
+
+ def __getattr__(self, name):
+ mod = self.__dict__['mod']
+ return getattr(mod, name)
+
+ def __setattr__(self, name, val):
+ mod = self.__dict__['mod']
+ setattr(mod, name, val)
+
+ def __del__(self):
+ import sys
+ from _ctypes import dlclose
+ # XXX fish fish fish
+ mod = self.__dict__['mod']
+ dlclose(mod._lib._handle)
+ try:
+ del sys.modules[mod.__name__]
+ except KeyError:
+ pass
+
+
class CExtModuleBuilder(CBuilder):
standalone = False
_module = None
@@ -224,7 +248,7 @@
assert not self._module
self._make_wrapper_module()
if not isolated:
- mod = self._module_path.pyimport()
+ mod = ModuleWithCleanup(self._module_path.pyimport())
else:
mod = isolate.Isolate((str(self._module_path.dirpath()),
self._module_path.purebasename))
More information about the Pypy-commit
mailing list