replace Tulip with asyncio

This commit is contained in:
Victor Stinner
2015-07-09 02:39:43 +02:00
parent 6f52fbfaac
commit fe673cc692
4 changed files with 23 additions and 24 deletions

View File

@@ -9,6 +9,6 @@ The photo of Trollis flower was taken by Imartin6 and distributed under the CC
BY-SA 3.0 license. It comes from: BY-SA 3.0 license. It comes from:
http://commons.wikimedia.org/wiki/File:Trollius_altaicus.jpg http://commons.wikimedia.org/wiki/File:Trollius_altaicus.jpg
Trollius is a port of the Tulip project on Python 2, see also authors of the Trollius is a port of the asyncio project on Python 2, see also authors of the
Tulip project (AUTHORS file of the Tulip project). asyncio project (AUTHORS file).

View File

@@ -1,17 +1,17 @@
++++++++++++++++++ ++++++++++++++++++++
Trollius and Tulip Trollius and asyncio
++++++++++++++++++ ++++++++++++++++++++
Differences between Trollius and Tulip Differences between Trollius and asyncio
====================================== ========================================
Syntax of coroutines Syntax of coroutines
-------------------- --------------------
The major difference between Trollius and Tulip is the syntax of coroutines: The major difference between Trollius and asyncio is the syntax of coroutines:
================== ====================== ================== ======================
Tulip Trollius asyncio Trollius
================== ====================== ================== ======================
``yield from ...`` ``yield From(...)`` ``yield from ...`` ``yield From(...)``
``yield from []`` ``yield From(None)`` ``yield from []`` ``yield From(None)``
@@ -129,41 +129,41 @@ Other differences
``BaseEventLoop.run_in_executor()`` uses a synchronous executor instead of a ``BaseEventLoop.run_in_executor()`` uses a synchronous executor instead of a
pool of threads. It blocks until the function returns. For example, DNS pool of threads. It blocks until the function returns. For example, DNS
resolutions are blocking in this case. resolutions are blocking in this case.
* Trollius has more symbols than Tulip for compatibility with Python older than * Trollius has more symbols than asyncio for compatibility with Python older
3.3: than 3.3:
- ``From``: part of ``yield From(...)`` syntax - ``From``: part of ``yield From(...)`` syntax
- ``Return``: part of ``raise Return(...)`` syntax - ``Return``: part of ``raise Return(...)`` syntax
Write code working on Trollius and Tulip Write code working on Trollius and asyncio
======================================== ==========================================
Trollius and Tulip are different, especially for coroutines (``yield Trollius and asyncio are different, especially for coroutines (``yield
From(...)`` vs ``yield from ...``). From(...)`` vs ``yield from ...``).
To use asyncio or Trollius on Python 2 and Python 3, add the following code at To use asyncio or Trollius on Python 2 and Python 3, add the following code at
the top of your file:: the top of your file::
try: try:
# Use builtin asyncio on Python 3.4+, or Tulip on Python 3.3 # Use builtin asyncio on Python 3.4+, or asyncio on Python 3.3
import asyncio import asyncio
except ImportError: except ImportError:
# Use Trollius on Python <= 3.2 # Use Trollius on Python <= 3.2
import trollius as asyncio import trollius as asyncio
It is possible to write code working on both projects using only callbacks. It is possible to write code working on both projects using only callbacks.
This option is used by the following projects which work on Trollius and Tulip: This option is used by the following projects which work on Trollius and asyncio:
* `AutobahnPython <https://github.com/tavendo/AutobahnPython>`_: WebSocket & * `AutobahnPython <https://github.com/tavendo/AutobahnPython>`_: WebSocket &
WAMP for Python, it works on Trollius (Python 2.6 and 2.7), Tulip (Python WAMP for Python, it works on Trollius (Python 2.6 and 2.7), asyncio (Python
3.3) and Python 3.4 (asyncio), and also on Twisted. 3.3) and Python 3.4 (asyncio), and also on Twisted.
* `Pulsar <http://pythonhosted.org/pulsar/>`_: Event driven concurrent * `Pulsar <http://pythonhosted.org/pulsar/>`_: Event driven concurrent
framework for Python. With pulsar you can write asynchronous servers framework for Python. With pulsar you can write asynchronous servers
performing one or several activities in different threads and/or processes. performing one or several activities in different threads and/or processes.
Trollius 0.3 requires Pulsar 0.8.2 or later. Pulsar uses the ``asyncio`` Trollius 0.3 requires Pulsar 0.8.2 or later. Pulsar uses the ``asyncio``
module if available, or import ``trollius``. module if available, or import ``trollius``.
* `Tornado <http://www.tornadoweb.org/>`_ supports Tulip and Trollius since * `Tornado <http://www.tornadoweb.org/>`_ supports asyncio and Trollius since
Tornado 3.2: `tornado.platform.asyncio — Bridge between asyncio and Tornado Tornado 3.2: `tornado.platform.asyncio — Bridge between asyncio and Tornado
<http://tornado.readthedocs.org/en/latest/asyncio.html>`_. It tries to import <http://tornado.readthedocs.org/en/latest/asyncio.html>`_. It tries to import
asyncio or fallback on importing trollius. asyncio or fallback on importing trollius.
@@ -171,10 +171,10 @@ This option is used by the following projects which work on Trollius and Tulip:
Another option is to provide functions returning ``Future`` objects, so the Another option is to provide functions returning ``Future`` objects, so the
caller can decide to use callback using ``fut.add_done_callback(callback)`` or caller can decide to use callback using ``fut.add_done_callback(callback)`` or
to use coroutines (``yield From(fut)`` for Trollius, or ``yield from fut`` for to use coroutines (``yield From(fut)`` for Trollius, or ``yield from fut`` for
Tulip). This option is used by the `aiodns <https://github.com/saghul/aiodns>`_ asyncio). This option is used by the `aiodns <https://github.com/saghul/aiodns>`_
project for example. project for example.
Since Trollius 0.4, it's possible to use Tulip and Trollius coroutines in the Since Trollius 0.4, it's possible to use asyncio and Trollius coroutines in the
same process. The only limit is that the event loop must be a Trollius event same process. The only limit is that the event loop must be a Trollius event
loop. loop.

View File

@@ -33,7 +33,7 @@ Here is a more detailed list of the package contents:
* an interface for passing work off to a threadpool, for times when you * an interface for passing work off to a threadpool, for times when you
absolutely, positively have to use a library that makes blocking I/O calls. absolutely, positively have to use a library that makes blocking I/O calls.
Trollius is a portage of the `Tulip project <http://code.google.com/p/tulip/>`_ Trollius is a portage of the `asyncio project <https://github.com/python/asyncio>`_
(``asyncio`` module, `PEP 3156 <http://legacy.python.org/dev/peps/pep-3156/>`_) (``asyncio`` module, `PEP 3156 <http://legacy.python.org/dev/peps/pep-3156/>`_)
on Python 2. Trollius works on Python 2.6-3.5. It has been tested on Windows, on Python 2. Trollius works on Python 2.6-3.5. It has been tested on Windows,
Linux, Mac OS X, FreeBSD and OpenIndiana. Linux, Mac OS X, FreeBSD and OpenIndiana.
@@ -50,8 +50,7 @@ Linux, Mac OS X, FreeBSD and OpenIndiana.
* IRC: ``#asyncio`` channel on the `Freenode network <https://freenode.net/>`_ * IRC: ``#asyncio`` channel on the `Freenode network <https://freenode.net/>`_
* Copyright/license: Open source, Apache 2.0. Enjoy! * Copyright/license: Open source, Apache 2.0. Enjoy!
See also the `Tulip project <http://code.google.com/p/tulip/>`_ (asyncio module See also the `asyncio project at Github <https://github.com/python/asyncio>`_.
for Python 3.3).
Table Of Contents Table Of Contents

View File

@@ -371,7 +371,7 @@ if events.asyncio is not None:
if hasattr(events.asyncio, 'coroutines'): if hasattr(events.asyncio, 'coroutines'):
_COROUTINE_TYPES += (events.asyncio.coroutines.CoroWrapper,) _COROUTINE_TYPES += (events.asyncio.coroutines.CoroWrapper,)
else: else:
# old Tulip/Python versions # old asyncio/Python versions
_COROUTINE_TYPES += (events.asyncio.tasks.CoroWrapper,) _COROUTINE_TYPES += (events.asyncio.tasks.CoroWrapper,)
def iscoroutine(obj): def iscoroutine(obj):