summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Ronacher <armin.ronacher@active-4.com>2014-07-01 00:31:23 +0200
committerArmin Ronacher <armin.ronacher@active-4.com>2014-07-01 00:31:23 +0200
commit73c752a9d643c06979a4f64ace35a2568e81ec4c (patch)
tree25287667668a4e4579155021199e53722455b319
parent1e6456bf54bb37743d22fe564b475f10bc13281e (diff)
downloadpluginbase-73c752a9d643c06979a4f64ace35a2568e81ec4c.tar.gz
Fixed shutdown error on late garbage collection.
-rw-r--r--pluginbase.py13
-rw-r--r--tests/shutdown.py9
-rw-r--r--tests/test_shutdown.py15
3 files changed, 31 insertions, 6 deletions
diff --git a/pluginbase.py b/pluginbase.py
index 9f11abf..426a105 100644
--- a/pluginbase.py
+++ b/pluginbase.py
@@ -265,16 +265,17 @@ class PluginSource(object):
return __import__(self.base.package + '.' + name,
globals(), {}, ['__name__'])
- def cleanup(self, _sys=sys):
+ def cleanup(self):
"""Cleans up all loaded plugins manually. This is necessary to
call only if :attr:`persist` is enabled. Otherwise this happens
automatically when the source gets garbage collected.
-
- :param _sys: the sys module to use for cleaning up. This parameter
- seems useless a the default is always the right one
- anyways but it supports the shutdown when the
- interpreter terminates.
"""
+ self.__cleanup()
+
+ def __cleanup(self, _sys=sys, _shutdown_module=_shutdown_module):
+ # The default parameters are necessary because this can be fired
+ # from the destructor and so late when the interpreter shuts down
+ # that these functions and modules might be gone.
if self.mod is None:
return
modname = self.mod.__name__
diff --git a/tests/shutdown.py b/tests/shutdown.py
new file mode 100644
index 0000000..1dbaa0c
--- /dev/null
+++ b/tests/shutdown.py
@@ -0,0 +1,9 @@
+from pluginbase import PluginBase
+
+base = PluginBase(package='dummy.modules')
+plugin_source = base.make_plugin_source(
+ searchpath=['./plugins'])
+
+# This dangles around. This will be collected when the interpreter
+# shuts down.
+hello = plugin_source.load_plugin('hello')
diff --git a/tests/test_shutdown.py b/tests/test_shutdown.py
new file mode 100644
index 0000000..4701884
--- /dev/null
+++ b/tests/test_shutdown.py
@@ -0,0 +1,15 @@
+import os
+import sys
+import subprocess
+
+
+def test_clean_shutdown():
+ env = dict(os.environ)
+ env['PYTHONPATH'] = '..:.'
+ c = subprocess.Popen([sys.executable, '-c', 'import shutdown'],
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE,
+ env=env)
+ stdout, stderr = c.communicate()
+ assert stdout == b''
+ assert stderr == b''