diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-11-24 18:10:19 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-11-24 18:10:19 +0100 |
commit | c83258845e31b7d2f8ea5116cb1836c0cea27a3b (patch) | |
tree | d06bf3a164ef2b42eee44a4c91f04698037c4831 | |
parent | 4b0d4fe8313b63474357c7a02d51ae372e7e2b0f (diff) | |
download | aioeventlet-c83258845e31b7d2f8ea5116cb1836c0cea27a3b.tar.gz |
create GeventEventLoop
-rw-r--r-- | aiogreen.py | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/aiogreen.py b/aiogreen.py index a754507..d6ffa15 100644 --- a/aiogreen.py +++ b/aiogreen.py @@ -189,17 +189,15 @@ class _Selector(asyncio.selectors._BaseSelectorImpl): self._event = None -class EventletEventLoop(asyncio.SelectorEventLoop): - def __init__(self): +class _EventLoop(asyncio.SelectorEventLoop): + def __init__(self, hub, selector): self._greenthread = None # Store a reference to the hub to ensure # that we always use the same hub - self._hub = eventlet.hubs.get_hub() - - selector = _Selector(self, self._hub) + self._hub = hub - super(EventletEventLoop, self).__init__(selector=selector) + super(_EventLoop, self).__init__(selector=selector) # Force a call to set_debug() to set hub.debug_blocking self.set_debug(self.get_debug()) @@ -208,7 +206,7 @@ class EventletEventLoop(asyncio.SelectorEventLoop): self._default_executor = _TpoolExecutor(self) def call_soon(self, callback, *args): - handle = super(EventletEventLoop, self).call_soon(callback, *args) + handle = super(_EventLoop, self).call_soon(callback, *args) if self._selector is not None and self._selector._event: # selector.select() is running: write into the self-pipe to wake up # the selector @@ -216,7 +214,7 @@ class EventletEventLoop(asyncio.SelectorEventLoop): return handle def call_at(self, when, callback, *args): - handle = super(EventletEventLoop, self).call_at(when, callback, *args) + handle = super(_EventLoop, self).call_at(when, callback, *args) if self._selector is not None and self._selector._event: # selector.select() is running: write into the self-pipe to wake up # the selector @@ -224,7 +222,7 @@ class EventletEventLoop(asyncio.SelectorEventLoop): return handle def set_debug(self, debug): - super(EventletEventLoop, self).set_debug(debug) + super(_EventLoop, self).set_debug(debug) self._hub.debug_exceptions = debug @@ -245,7 +243,7 @@ class EventletEventLoop(asyncio.SelectorEventLoop): def run_forever(self): self._greenthread = eventlet.getcurrent() try: - super(EventletEventLoop, self).run_forever() + super(_EventLoop, self).run_forever() finally: if self._hub.debug_blocking: # eventlet event loop is still running: cancel the current @@ -332,5 +330,23 @@ class EventletEventLoop(asyncio.SelectorEventLoop): return fut +class EventletEventLoop(_EventLoop): + def __init__(self): + hub = eventlet.hubs.get_hub() + selector = _Selector(self, hub) + super(EventletEventLoop, self).__init__(hub, selector) + + +class GeventEventLoop(_EventLoop): + def __init__(self): + hub = eventlet.hubs.get_hub() + selector = _Selector(self, hub) + super(GeventEventLoop, self).__init__(hub, selector) + + class EventletEventLoopPolicy(asyncio.DefaultEventLoopPolicy): _loop_factory = EventletEventLoop + + +class GeventEventLoopPolicy(asyncio.DefaultEventLoopPolicy): + _loop_factory = GeventEventLoop |