Latest recipes tagged "multithreading"http://code.activestate.com/recipes/tags/multithreading/new/2013-03-13T06:06:16-07:00ActiveState Code RecipesThreaded communication with subprocess (Python)
2013-03-13T06:06:16-07:00Jan Müllerhttp://code.activestate.com/recipes/users/4183984/http://code.activestate.com/recipes/578488-threaded-communication-with-subprocess/
<p style="color: grey">
Python
recipe 578488
by <a href="/recipes/users/4183984/">Jan Müller</a>
(<a href="/recipes/tags/async/">async</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/messaging/">messaging</a>, <a href="/recipes/tags/multithreading/">multithreading</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/queue/">queue</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 3.
</p>
<p>This recipe shows how to domesticate another executable as a service in a subprocess.</p>
Multithreading Downloader Class (Python)
2012-07-22T07:44:20-07:00Itay Brandeshttp://code.activestate.com/recipes/users/4182927/http://code.activestate.com/recipes/578220-multithreading-downloader-class/
<p style="color: grey">
Python
recipe 578220
by <a href="/recipes/users/4182927/">Itay Brandes</a>
(<a href="/recipes/tags/downloader/">downloader</a>, <a href="/recipes/tags/multithread/">multithread</a>, <a href="/recipes/tags/multithreading/">multithreading</a>, <a href="/recipes/tags/urllib/">urllib</a>, <a href="/recipes/tags/urllib2/">urllib2</a>, <a href="/recipes/tags/urlopen/">urlopen</a>).
</p>
<p>Garbs files from the web using multithreading in an attempt to enhance transfer rate.</p>
A multithreaded, concurrent version of map() (Python)
2010-08-16T23:04:48-07:00Wai Yip Tunghttp://code.activestate.com/recipes/users/2382677/http://code.activestate.com/recipes/577360-a-multithreaded-concurrent-version-of-map/
<p style="color: grey">
Python
recipe 577360
by <a href="/recipes/users/2382677/">Wai Yip Tung</a>
(<a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/multithreading/">multithreading</a>, <a href="/recipes/tags/threads/">threads</a>).
</p>
<p>map() applies a function to a list of data sequentially. This is a variation to map that execute each function call concurrently in a thread.</p>
Synchronizing worker threads using a common input source (Python)
2010-08-09T16:24:38-07:00Uri Sternfeldhttp://code.activestate.com/recipes/users/4174615/http://code.activestate.com/recipes/577350-synchronizing-worker-threads-using-a-common-input-/
<p style="color: grey">
Python
recipe 577350
by <a href="/recipes/users/4174615/">Uri Sternfeld</a>
(<a href="/recipes/tags/multithreading/">multithreading</a>, <a href="/recipes/tags/synchronization/">synchronization</a>).
</p>
<p>This class is used to synchronize worker threads that get their input from a common source that changes over time, and may even be empty on some occasions.</p>
<p>The problem is that the threads are unaware of the existence of other threads, and have no way of knowing whether any new input will be inserted by other threads. Instead of using a separate 'control' thread, or having the threads exit needlessly each time the input source is empty, a WorkersLounge instance can be used to synchronize them.</p>
<p>The commonest example is using a shared Queue.Queue object, where each thread may put additional jobs into it depending on its current job. When the queue is empty, the other threads 'rest' in the 'lounge'. When the last thread with a job is trying to 'rest', all the threads exit. When a thread puts new jobs into the queue, it should wake up any resting thread by calling the 'back_to_work' method.</p>