summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-06-11 18:31:58 +0200
committerVictor Stinner <victor.stinner@gmail.com>2014-06-11 18:31:58 +0200
commit30db7c01c74ce7c3682d4425f8dacb50007d2c89 (patch)
tree98256bb6ea32ec0ae4728b772af19d57693c9ecd
parent1fcf2ceb619af1353bcf58c967dd30eabbd86c98 (diff)
downloadtrollius-30db7c01c74ce7c3682d4425f8dacb50007d2c89.tar.gz
Interop: support also event loop policy
-rw-r--r--examples/interop_asyncio.py8
-rw-r--r--trollius/events.py42
2 files changed, 27 insertions, 23 deletions
diff --git a/examples/interop_asyncio.py b/examples/interop_asyncio.py
index a0cbc3f..b20e3ed 100644
--- a/examples/interop_asyncio.py
+++ b/examples/interop_asyncio.py
@@ -26,11 +26,13 @@ def trollius_coroutine(coro):
raise trollius.Return("trollius")
def main():
+ # use trollius event loop policy in asyncio
+ policy = trollius.get_event_loop_policy()
+ asyncio.set_event_loop_policy(policy)
+
# create an event loop for the main thread: use Trollius event loop
loop = trollius.get_event_loop()
-
- # set the asyncio event loop (for the main thread)
- asyncio.set_event_loop(loop)
+ assert asyncio.get_event_loop() is loop
print("[ asyncio coroutine called from trollius coroutine ]")
coro1 = asyncio_noop()
diff --git a/trollius/events.py b/trollius/events.py
index 4e0e860..4deea24 100644
--- a/trollius/events.py
+++ b/trollius/events.py
@@ -118,9 +118,11 @@ class AbstractServer(object):
if asyncio is not None:
- # Reuse asyncio class so asyncio.set_event_loop() accepts Trollius event
- # loops
+ # Reuse asyncio classes so asyncio.set_event_loop() and
+ # asyncio.set_event_loop_policy() accept Trollius event loop and trollius
+ # event loop policy
AbstractEventLoop = asyncio.AbstractEventLoop
+ AbstractEventLoopPolicy = asyncio.AbstractEventLoopPolicy
else:
class AbstractEventLoop(object):
"""Abstract event loop."""
@@ -359,30 +361,30 @@ else:
raise NotImplementedError
-class AbstractEventLoopPolicy(object):
- """Abstract policy for accessing the event loop."""
+ class AbstractEventLoopPolicy(object):
+ """Abstract policy for accessing the event loop."""
- def get_event_loop(self):
- """XXX"""
- raise NotImplementedError
+ def get_event_loop(self):
+ """XXX"""
+ raise NotImplementedError
- def set_event_loop(self, loop):
- """XXX"""
- raise NotImplementedError
+ def set_event_loop(self, loop):
+ """XXX"""
+ raise NotImplementedError
- def new_event_loop(self):
- """XXX"""
- raise NotImplementedError
+ def new_event_loop(self):
+ """XXX"""
+ raise NotImplementedError
- # Child processes handling (Unix only).
+ # Child processes handling (Unix only).
- def get_child_watcher(self):
- """XXX"""
- raise NotImplementedError
+ def get_child_watcher(self):
+ """XXX"""
+ raise NotImplementedError
- def set_child_watcher(self, watcher):
- """XXX"""
- raise NotImplementedError
+ def set_child_watcher(self, watcher):
+ """XXX"""
+ raise NotImplementedError
class BaseDefaultEventLoopPolicy(AbstractEventLoopPolicy):