summaryrefslogtreecommitdiff
path: root/aiogreen.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-11-19 23:14:59 +0100
committerVictor Stinner <victor.stinner@gmail.com>2014-11-19 23:14:59 +0100
commit177807ea66794a151974a6487bc9a66329255d14 (patch)
tree129f2fb6d5bb557d9ffd9b6b29fbacd8800387fa /aiogreen.py
parentfc90935a5e1f243a95c401c228cded77cdb9d064 (diff)
downloadaioeventlet-177807ea66794a151974a6487bc9a66329255d14.tar.gz
If eventlet monkey patched the thread module, use eventlet.tpool as the default
executor
Diffstat (limited to 'aiogreen.py')
-rw-r--r--aiogreen.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/aiogreen.py b/aiogreen.py
index 4cbc3c8..fb60ea0 100644
--- a/aiogreen.py
+++ b/aiogreen.py
@@ -237,6 +237,26 @@ class _Scheduler(object):
self._unschedule_timer_unlocked()
+class _TpoolExecutor(object):
+ def __init__(self, loop):
+ import eventlet.tpool
+ self._loop = loop
+ self._tpool = eventlet.tpool
+
+ def submit(self, fn, *args, **kwargs):
+ f = asyncio.Future(loop=self._loop)
+ try:
+ res = self._tpool.execute(fn, *args, **kwargs)
+ except Exception as exc:
+ f.set_exception(exc)
+ else:
+ f.set_result(res)
+ return f
+
+ def shutdown(self, wait=True):
+ pass
+
+
class EventLoop(BaseEventLoop):
def __init__(self):
super(EventLoop, self).__init__()
@@ -257,6 +277,9 @@ class EventLoop(BaseEventLoop):
# Scheduler used to schedule a call to the loop._run_once() method
self._scheduler = _Scheduler(self)
+ if eventlet.patcher.is_monkey_patched('thread'):
+ self._default_executor = _TpoolExecutor(self)
+
def time(self):
return self._hub.clock()