Commit 413abfed authored by Denis Bilenko's avatar Denis Bilenko

lazily import gevent.core.loop in the hub, in case someone wants to plug in their own loop

parent 77d5616b
...@@ -176,6 +176,16 @@ def set_hub(hub): ...@@ -176,6 +176,16 @@ def set_hub(hub):
_threadlocal.hub = hub _threadlocal.hub = hub
def _import(path):
if not isinstance(path, basestring):
return path
module, item = path.rsplit('.', 1)
x = __import__(module)
for attr in path.split('.')[1:]:
x = getattr(x, attr)
return x
class Hub(greenlet): class Hub(greenlet):
"""A greenlet that runs the event loop. """A greenlet that runs the event loop.
...@@ -183,7 +193,7 @@ class Hub(greenlet): ...@@ -183,7 +193,7 @@ class Hub(greenlet):
""" """
SYSTEM_ERROR = (KeyboardInterrupt, SystemExit, SystemError) SYSTEM_ERROR = (KeyboardInterrupt, SystemExit, SystemError)
loop_class = core.loop loop_class = 'gevent.core.loop'
def __init__(self, loop=None, default=None): def __init__(self, loop=None, default=None):
greenlet.__init__(self) greenlet.__init__(self)
...@@ -194,6 +204,7 @@ class Hub(greenlet): ...@@ -194,6 +204,7 @@ class Hub(greenlet):
else: else:
if default is None: if default is None:
default = get_ident() == MAIN_THREAD default = get_ident() == MAIN_THREAD
loop_class = _import(self.loop_class)
self.loop = loop_class(flags=loop, default=default) self.loop = loop_class(flags=loop, default=default)
self.loop.error_handler = self self.loop.error_handler = self
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment