Skip to content

Commit 8c7ea91

Browse files
authored
Merge pull request #300 from alde/explicitly-import-collectors
Use the imp library to import collectors
2 parents ab59e12 + 427506f commit 8c7ea91

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/diamond/utils/classes.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import inspect
88
import traceback
99
import pkg_resources
10+
import imp
1011

1112
from diamond.util import load_class_from_name
1213
from diamond.collector import Collector
@@ -151,9 +152,11 @@ def load_collectors_from_paths(paths):
151152

152153
modname = f[:-3]
153154

155+
fp, pathname, description = imp.find_module(modname, [path])
156+
154157
try:
155158
# Import the module
156-
mod = __import__(modname, globals(), locals(), ['*'])
159+
mod = imp.load_module(modname, fp, pathname, description)
157160
except (KeyboardInterrupt, SystemExit), err:
158161
logger.error(
159162
"System or keyboard interrupt "
@@ -170,6 +173,9 @@ def load_collectors_from_paths(paths):
170173
else:
171174
for name, cls in get_collectors_from_module(mod):
172175
collectors[name] = cls
176+
finally:
177+
if fp:
178+
fp.close()
173179

174180
# Return Collector classes
175181
return collectors

0 commit comments

Comments
 (0)