Popular recipes tagged "actor"http://code.activestate.com/recipes/tags/actor/popular/2011-10-30T19:59:44-07:00ActiveState Code Recipesactorish decorator for making async code look more like sync one and a less blocking (Python)
2011-10-30T19:59:44-07:00Przemyslaw Podczasihttp://code.activestate.com/recipes/users/4179716/http://code.activestate.com/recipes/577931-actorish-decorator-for-making-async-code-look-more/
<p style="color: grey">
Python
recipe 577931
by <a href="/recipes/users/4179716/">Przemyslaw Podczasi</a>
(<a href="/recipes/tags/actor/">actor</a>, <a href="/recipes/tags/threading/">threading</a>).
</p>
<p>I like how gevent is making async code to look like sync but non blocking without all the ugly callbacks.
I tried doing that with threads and object proxy (I found great one at: <a href="http://pypi.python.org/pypi/ProxyTypes" rel="nofollow">http://pypi.python.org/pypi/ProxyTypes</a> written by Phillip J. Eby, and this is where the actual magic happens).</p>
<p>For every function that is decorated it returns a proxy and the io call (or anything else) won't block until the value is actually needed.
(should be some pools and args pickling there, to make it more like message passing but I didn't want to fuzzy the example)
To use it as actor model, I guess it would require to queue requests to decorated object's methods and create a single thread to process them an in LazyProxy callback set q.get() instead of t.join()</p>