Popular recipes tagged "coroutine" but not "event"http://code.activestate.com/recipes/tags/coroutine-event/2013-01-21T19:51:00-08:00ActiveState Code RecipesPipeline made of coroutines (Python)
2012-09-14T09:53:58-07:00Chaobin Tang (唐超斌)http://code.activestate.com/recipes/users/4174076/http://code.activestate.com/recipes/578265-pipeline-made-of-coroutines/
<p style="color: grey">
Python
recipe 578265
by <a href="/recipes/users/4174076/">Chaobin Tang (唐超斌)</a>
(<a href="/recipes/tags/coroutine/">coroutine</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/python/">python</a>).
Revision 2.
</p>
<p>A pipeline made of several coroutines that can be turned off gracefully. </p>
Yet another Python implementation of PEP 380 (yield from) (Python)
2010-04-25T23:08:07-07:00Arnau Sanchezhttp://code.activestate.com/recipes/users/4173270/http://code.activestate.com/recipes/577153-yet-another-python-implementation-of-pep-380-yield/
<p style="color: grey">
Python
recipe 577153
by <a href="/recipes/users/4173270/">Arnau Sanchez</a>
(<a href="/recipes/tags/coroutine/">coroutine</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/refactor/">refactor</a>).
Revision 3.
</p>
<p>Any Python programmer knows how extremely powerful <a href="http://www.python.org/dev/peps/pep-0255/">generators</a> are. Now (since version 2.5) Python generators can not only yield values but also receive them, so they can be used to build <a href="http://www.python.org/dev/peps/pep-0342/">coroutines</a>.</p>
<p>One drawback of the current implementation of generators is that you can only yield/receive values to/from the immediate caller. That means, basically, that you cannot easily refactor your code and write nested generators. <a href="http://www.python.org/dev/peps/pep-0380/">PEP-380</a> is the most serious effort to overcome this issue, but until it gets approved we can still play around with pure Python implementations of <em>yield from</em>. </p>
<p>This recipe follows terminology used by others in the past (<a href="http://code.activestate.com/recipes/576727">recipe566726</a>, <a href="http://code.activestate.com/recipes/576728">recipe576728</a>), but I've tried to simplify the code as much as possible.</p>
Asynchronous subprocess using asyncore (Python)
2013-01-21T19:51:00-08:00Glenn Eychanerhttp://code.activestate.com/recipes/users/4172294/http://code.activestate.com/recipes/576957-asynchronous-subprocess-using-asyncore/
<p style="color: grey">
Python
recipe 576957
by <a href="/recipes/users/4172294/">Glenn Eychaner</a>
(<a href="/recipes/tags/async/">async</a>, <a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/asyncore/">asyncore</a>, <a href="/recipes/tags/coroutine/">coroutine</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 21.
</p>
<p>A coroutine-based wrapper for subprocess.Popen that uses asyncore to communicate with child processes asynchronously. This allows subprocesses to be called from within socket servers or clients without needing a complicated event loop to check both. Uses <a href="http://code.activestate.com/recipes/576965/">recipe 576965</a> to provide the asynchronous coroutine framework, <a href="http://code.activestate.com/recipes/576967/">recipe 576967</a> to provide asynchronous pipes, and <a href="http://code.activestate.com/recipes/577600/">recipe 577600</a> to provide multiple alarms.</p>
Multicontext (e.g. asynchronous) inline execution framework using coroutines (Python)
2012-12-06T19:32:20-08:00Glenn Eychanerhttp://code.activestate.com/recipes/users/4172294/http://code.activestate.com/recipes/576965-multicontext-eg-asynchronous-inline-execution-fram/
<p style="color: grey">
Python
recipe 576965
by <a href="/recipes/users/4172294/">Glenn Eychaner</a>
(<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/coroutine/">coroutine</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/inline/">inline</a>, <a href="/recipes/tags/nonblocking/">nonblocking</a>, <a href="/recipes/tags/pattern/">pattern</a>, <a href="/recipes/tags/thread/">thread</a>).
Revision 14.
</p>
<p>A framework for executing inline code, contained in a generator, across multiple execution contexts, by pairing it with an executor that handles the context switching at each yield. An example of a generator which executes some iterations synchronously and some asynchronously is provided. The framework is general enough to be applied to many different coroutine situations.</p>