Latest recipes tagged "queue"http://code.activestate.com/recipes/tags/queue/new/2013-12-08T21:12:55-08:00ActiveState Code RecipesPriority Queue (with deletion) (Python) 2013-12-08T21:12:55-08:00elazarhttp://code.activestate.com/recipes/users/4187847/http://code.activestate.com/recipes/578780-priority-queue-with-deletion/ <p style="color: grey"> Python recipe 578780 by <a href="/recipes/users/4187847/">elazar</a> (<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/heap/">heap</a>, <a href="/recipes/tags/heapq/">heapq</a>, <a href="/recipes/tags/priority_queue/">priority_queue</a>, <a href="/recipes/tags/queue/">queue</a>). Revision 5. </p> <p>Based on the interface defined in aima-python <a href="http://aima-python.googlecode.com/svn/trunk/utils.py" rel="nofollow">http://aima-python.googlecode.com/svn/trunk/utils.py</a></p> <p>Yields better performance.</p> Threaded 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> Queue for managing multiple SIGALRM alarms concurrently (Python) 2012-12-06T18:58:11-08:00Glenn Eychanerhttp://code.activestate.com/recipes/users/4172294/http://code.activestate.com/recipes/577600-queue-for-managing-multiple-sigalrm-alarms-concurr/ <p style="color: grey"> Python recipe 577600 by <a href="/recipes/users/4172294/">Glenn Eychaner</a> (<a href="/recipes/tags/alarm/">alarm</a>, <a href="/recipes/tags/queue/">queue</a>, <a href="/recipes/tags/signal/">signal</a>). Revision 3. </p> <p>In asynchronous code, <em>signal.alarm()</em> is extremely useful for setting and handling timeouts and other timed and periodic tasks. It has a major limitation, however, that only one alarm function and alarm time can be set at a time; setting a new alarm disables the previous alarm. This package uses a <em>heapq</em> to maintain a queue of alarm events, allowing multiple alarm functions and alarm times to be set concurrently.</p> Find the oldest (or yougest) of a list of files (Python) 2009-06-10T16:08:13-07:00Micah Elliotthttp://code.activestate.com/recipes/users/2649403/http://code.activestate.com/recipes/576804-find-the-oldest-or-yougest-of-a-list-of-files/ <p style="color: grey"> Python recipe 576804 by <a href="/recipes/users/2649403/">Micah Elliott</a> (<a href="/recipes/tags/age/">age</a>, <a href="/recipes/tags/files/">files</a>, <a href="/recipes/tags/find/">find</a>, <a href="/recipes/tags/queue/">queue</a>). </p> <p>Sometimes you need to perform an operation on the oldest of a set of files. Using <em>get_oldest_file</em> you could implement an age-based priority queue that processes files from oldest to newest. The list of files you pass in may be from a <em>glob</em> of a single directory or some more elaborate search routine.</p> Queue with tagged items (Python) 2009-01-28T07:23:40-08:00Jirka Vejrazkahttp://code.activestate.com/recipes/users/4168986/http://code.activestate.com/recipes/576632-queue-with-tagged-items/ <p style="color: grey"> Python recipe 576632 by <a href="/recipes/users/4168986/">Jirka Vejrazka</a> (<a href="/recipes/tags/consumer/">consumer</a>, <a href="/recipes/tags/producer/">producer</a>, <a href="/recipes/tags/queue/">queue</a>, <a href="/recipes/tags/tag/">tag</a>). Revision 2. </p> <p>I needed multiple consumers to retrieve data from a queue fed by one producer. Could not find a good working code for that, so I implemented my own queue. Docstring should describe how this works.</p> <p>Two notes: 1) my code uses multiprocessing code, but in this module, the Lock and Condition could be easily replaced with the same objects from the threading module 2) the attached test uses syntax for "nose" testing package, I did not convert it to doctest or UnitTest.</p> Simple lock-queue via Memcached (Python) 2008-11-19T01:32:07-08:00Tal Einathttp://code.activestate.com/recipes/users/2892534/http://code.activestate.com/recipes/576567-simple-lock-queue-via-memcached/ <p style="color: grey"> Python recipe 576567 by <a href="/recipes/users/2892534/">Tal Einat</a> (<a href="/recipes/tags/concurrency/">concurrency</a>, <a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/lock/">lock</a>, <a href="/recipes/tags/locking/">locking</a>, <a href="/recipes/tags/memcache/">memcache</a>, <a href="/recipes/tags/memcached/">memcached</a>, <a href="/recipes/tags/queue/">queue</a>). </p> <p>A simple lock-queue (FIFO) context manager implemented with <a href="http://www.danga.com/memcached/">Memcached</a>.</p> <p>In essence this is a normal lock, where the requests to acquire the lock are granted in the order in which they were originally made. Note that requests to acquire the lock are always blocking.</p> Interruptible Queue (Python) 2008-12-04T23:27:13-08:00Carl Bankshttp://code.activestate.com/recipes/users/686106/http://code.activestate.com/recipes/576461-interruptible-queue/ <p style="color: grey"> Python recipe 576461 by <a href="/recipes/users/686106/">Carl Banks</a> (<a href="/recipes/tags/queue/">queue</a>). Revision 3. </p> <p>A Queue that allows the producer thread to raise an exception in the consumer threads, or vice versa.</p>