Latest recipes tagged "twisted"http://code.activestate.com/recipes/tags/twisted/new/2012-01-20T09:48:27-08:00ActiveState Code RecipesAsync subprocess check_output replacement for Twisted (Python)
2012-01-20T09:48:27-08:00Alan Franzonihttp://code.activestate.com/recipes/users/4169882/http://code.activestate.com/recipes/578021-async-subprocess-check_output-replacement-for-twis/
<p style="color: grey">
Python
recipe 578021
by <a href="/recipes/users/4169882/">Alan Franzoni</a>
(<a href="/recipes/tags/check_output/">check_output</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/spawnprocess/">spawnprocess</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/twisted/">twisted</a>).
</p>
<p>As any twisted user knows, the original python subprocess module can yield to interferences with twisted's own reactor - at least unless installSignalHandlers is false, which can lead to other consequences. </p>
<p>This recipe simulates a stripped down version of subprocess.check_output() which returns a deferred and is twisted friendly.</p>
asyncore scheduler (Python)
2011-07-25T23:42:21-07:00Giampaolo RodolĂ http://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/577808-asyncore-scheduler/
<p style="color: grey">
Python
recipe 577808
by <a href="/recipes/users/4178764/">Giampaolo RodolĂ </a>
(<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/asyncore/">asyncore</a>, <a href="/recipes/tags/heapq/">heapq</a>, <a href="/recipes/tags/nonblocking/">nonblocking</a>, <a href="/recipes/tags/scheduler/">scheduler</a>, <a href="/recipes/tags/twisted/">twisted</a>).
Revision 5.
</p>
<p>The thing I miss mostly in asyncore is a system for calling a function after a certain amount of time without blocking. This is crucial for simple tasks such as disconnecting a peer after a certain time of inactivity or more advanced use cases such as <a href="http://code.google.com/p/pyftpdlib/source/browse/tags/release-0.6.0/pyftpdlib/ftpserver.py#1048">bandwidth throttling</a>.</p>
<p>This recipe was initially inspired by Twisted's internet.base.DelayedCall class:</p>
<p><a href="http://twistedmatrix.com/trac/browser/tags/last_vfs_and_web2/twisted/internet/base.py#L34" rel="nofollow">http://twistedmatrix.com/trac/browser/tags/last_vfs_and_web2/twisted/internet/base.py#L34</a></p>
<p>...then included into pyftpdlib:</p>
<p><a href="http://code.google.com/p/pyftpdlib/issues/detail?id=72" rel="nofollow">http://code.google.com/p/pyftpdlib/issues/detail?id=72</a></p>
<p>...and finally proposed for inclusion into asyncore:</p>
<p><a href="http://bugs.python.org/issue1641" rel="nofollow">http://bugs.python.org/issue1641</a></p>
Twisted Public Deferred (Python)
2009-12-08T09:47:16-08:00Alan Franzonihttp://code.activestate.com/recipes/users/4169882/http://code.activestate.com/recipes/576978-twisted-public-deferred/
<p style="color: grey">
Python
recipe 576978
by <a href="/recipes/users/4169882/">Alan Franzoni</a>
(<a href="/recipes/tags/deferred/">deferred</a>, <a href="/recipes/tags/twisted/">twisted</a>).
Revision 5.
</p>
<p>This small piece of code helps separating the "public" and "private" interface parts of deferred objects in Twisted.</p>
<p>Although it might not be really useful in production code, it is great for newcomers who are still learning the framework.</p>
How to use twisted pb FilePager (Python)
2009-04-30T05:20:09-07:00alex lavoro.propiohttp://code.activestate.com/recipes/users/4170029/http://code.activestate.com/recipes/576735-how-to-use-twisted-pb-filepager/
<p style="color: grey">
Python
recipe 576735
by <a href="/recipes/users/4170029/">alex lavoro.propio</a>
(<a href="/recipes/tags/filepager/">filepager</a>, <a href="/recipes/tags/network/">network</a>, <a href="/recipes/tags/pb/">pb</a>, <a href="/recipes/tags/twisted/">twisted</a>).
Revision 3.
</p>
<p>Banana limits string objects to 640k so sending a large file requires to break it into many small chunks. Twisted provide a helper class to do this: twisted.spread.pb.FilePager. I modified on <a href="http://code.activestate.com/recipes/457670/">recipe 457670</a>: "How to use twisted pb pager" to demonstrate the usage of FilePager. getFile1() is similar to getIt() in <a href="http://code.activestate.com/recipes/457670/">recipe 457670</a>. getFile2() uses the utility function in twisted.spread.pb.util.</p>