Popular recipes tagged "meta:requires=__future__" and "threads"http://code.activestate.com/recipes/tags/meta:requires=__future__+threads/2007-11-28T05:29:11-08:00ActiveState Code RecipesConsole progress dots using threads and a context manager (Python)
2007-11-28T05:29:11-08:00Paul Moorehttp://code.activestate.com/recipes/users/1826654/http://code.activestate.com/recipes/535141-console-progress-dots-using-threads-and-a-context-/
<p style="color: grey">
Python
recipe 535141
by <a href="/recipes/users/1826654/">Paul Moore</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>When executing a long running task, it is often useful to provide some feedback to the user. In a console program, this often consists of text such as "Running...." where a dot is printed (say) each second.</p>
<p>Adding a progress indicator like this to existing code can be tricky, but with threads and a context manager, it's easy.</p>
Yielding out of nested routines by metaclass transformation (Python)
2006-11-17T04:16:35-08:00Bernhard Mulderhttp://code.activestate.com/recipes/users/189076/http://code.activestate.com/recipes/498270-yielding-out-of-nested-routines-by-metaclass-trans/
<p style="color: grey">
Python
recipe 498270
by <a href="/recipes/users/189076/">Bernhard Mulder</a>
(<a href="/recipes/tags/threads/">threads</a>).
Revision 2.
</p>
<p>Python 2.5 improved the support for generators, making it easier to
use coroutines. If you want to use coroutines, however, you can not
transfer control out of nested functions. You can eliminate this
restriction by systematically converting regular functions into
generator functions as demonstrated by this recipe <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474127" rel="nofollow">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/474127</a> The script below might
serve as a starting point to do this transformation automatically,
making the use of coroutines (tasklets, lightweight threads...) more
natural.</p>
Pseudo threads with generators and PyGTK/gnome-python (Python)
2004-11-05T06:33:06-08:00Arjan Molenaarhttp://code.activestate.com/recipes/users/1729855/http://code.activestate.com/recipes/327082-pseudo-threads-with-generators-and-pygtkgnome-pyth/
<p style="color: grey">
Python
recipe 327082
by <a href="/recipes/users/1729855/">Arjan Molenaar</a>
(<a href="/recipes/tags/pygtk/">pygtk</a>, <a href="/recipes/tags/threads/">threads</a>).
</p>
<p>A thread-like interface for those who want to "use" threads in Python with PyGTK. I use it when loading files and display a nice progress bar. The function or method you give to GIdleThread should "yield" every now and then. This makes it simpler to write code, since you do not have to care about nasty locks.</p>
Generator Attributes (Python)
2002-12-09T08:44:56-08:00Raymond Hettingerhttp://code.activestate.com/recipes/users/178123/http://code.activestate.com/recipes/164044-generator-attributes/
<p style="color: grey">
Python
recipe 164044
by <a href="/recipes/users/178123/">Raymond Hettinger</a>
(<a href="/recipes/tags/threads/">threads</a>).
Revision 3.
</p>
<p>Function to enable attribute access for generator instances. Simplifies data sharing for advanced uses of generators and provides much of the functionality sought by PEP 288.
<br>
Most uses of generators have no need for data sharing. This recipe is for the few tough cases which can be written more elegantly when attribute access is enabled.</p>
Cooperative multithreading with generators and signal handling (Python)
2002-11-15T18:47:23-08:00Brian Bushhttp://code.activestate.com/recipes/users/235551/http://code.activestate.com/recipes/162764-cooperative-multithreading-with-generators-and-sig/
<p style="color: grey">
Python
recipe 162764
by <a href="/recipes/users/235551/">Brian Bush</a>
(<a href="/recipes/tags/threads/">threads</a>).
</p>
<p>Here is an implementation of cooperative multithreading using generators that handles signals (SIGINT only in this recipe).</p>