diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-11-21 01:49:09 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-11-21 01:49:09 +0100 |
commit | b1624c7056115de851c9a439d872cb9c2bba6818 (patch) | |
tree | bb4a82a2107a81c49ecaa1de1c66d714c0aa3eed /README | |
parent | 77ca2876b20591dc450e5a3137804182d9fb0fd8 (diff) | |
download | aioeventlet-b1624c7056115de851c9a439d872cb9c2bba6818.tar.gz |
write doc
Diffstat (limited to 'README')
-rw-r--r-- | README | 63 |
1 files changed, 62 insertions, 1 deletions
@@ -1,4 +1,4 @@ -asyncio event loop scheduling callbacks in eventlet. +asyncio event loop implemented on top of eventlet. * Trollius project: http://trollius.readthedocs.org/ * aiogreen at PyPI: https://pypi.python.org/pypi/aiogreen @@ -7,13 +7,74 @@ asyncio event loop scheduling callbacks in eventlet. Usage ===== +Use aiogreen with asyncio +------------------------- + aiogreen implements the asyncio API, see asyncio documentation: https://docs.python.org/dev/library/asyncio.html +To use aiogreen with asyncio, set the event loop policy before using an event +loop, example:: + + import aiogreen + import asyncio + + asyncio.set_event_loop_policy(aiogreen.EventLoopPolicy()) + # .... + +Adding this code should be enough to try examples of the asyncio documentation. + +Hello World:: + + import aiogreen + import asyncio + + def hello_world(): + print("Hello World") + loop.stop() + + asyncio.set_event_loop_policy(aiogreen.EventLoopPolicy()) + loop = asyncio.get_event_loop() + loop.call_soon(hello_world) + loop.run_forever() + loop.close() + + +Use aiogreen with trollius +------------------------- + To support Python 2, you can use Trollius which uses ``yield`` instead of ``yield from`` for coroutines: http://trollius.readthedocs.org/ +To use aiogreen with trollius, set the event loop policy before using an event +loop, example:: + + import aiogreen + import trollius + + trollius.set_event_loop_policy(aiogreen.EventLoopPolicy()) + # .... + +Hello World:: + + import aiogreen + import trollius as asyncio + + def hello_world(): + print("Hello World") + loop.stop() + + asyncio.set_event_loop_policy(aiogreen.EventLoopPolicy()) + loop = asyncio.get_event_loop() + loop.call_soon(hello_world) + loop.run_forever() + loop.close() + + +Eventlet and aiogreen +--------------------- + Using the event loop from greenthreads is not safe: calls to the event loop must be passed to ``call_soon_threadsafe()``. Example to stop the event loop: |