summaryrefslogtreecommitdiff
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
parentfc90935a5e1f243a95c401c228cded77cdb9d064 (diff)
downloadaioeventlet-177807ea66794a151974a6487bc9a66329255d14.tar.gz
If eventlet monkey patched the thread module, use eventlet.tpool as the default
executor
-rw-r--r--README6
-rw-r--r--aiogreen.py23
2 files changed, 24 insertions, 5 deletions
diff --git a/README b/README
index dd5e70b..12704e2 100644
--- a/README
+++ b/README
@@ -77,10 +77,6 @@ Not supported (yet)
To do
=====
-* Support eventlet without monkey-patching
+* Support eventlet with monkey-patching
* Glue to ease debug: keep traceback between Handle, coroutine and greenthread.
Is it even possible?
-* run_in_executor(): use eventlet.tpool as the default executor?
- It avoids the dependency to concurrent.futures. aiogreen is written as a
- temporary solution to switch from eventlet to asyncio. So it may be better to
- use directly concurrent.futures to reduce the usage of eventlet?
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()