Most viewed recipes tagged "events"http://code.activestate.com/recipes/tags/events/views/2013-10-12T08:43:09-07:00ActiveState Code RecipesBlocking, Polling, Pipes, Queues in multiprocessing and how they are affected by the OS's time-slicing schedule (Python)
2010-05-08T18:18:01-07:00Kaushik Ghosehttp://code.activestate.com/recipes/users/4166965/http://code.activestate.com/recipes/577223-blocking-polling-pipes-queues-in-multiprocessing-a/
<p style="color: grey">
Python
recipe 577223
by <a href="/recipes/users/4166965/">Kaushik Ghose</a>
(<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>, <a href="/recipes/tags/multitasking/">multitasking</a>, <a href="/recipes/tags/polling/">polling</a>, <a href="/recipes/tags/timeslice/">timeslice</a>).
</p>
<p>This short code demonstrates how blocking calls to a Queue, while consuming less CPU, are limited in their response time by the minimum time slice the OS is willing to allocate (typically 10ms for Mac OS X and Linux). Non-blocking calls to Pipe, using poll() to check if there is data, on the other hand, give us millisecond or less response times, though they consume more CPU. In this respect doing a blocking call to a CPU is no different than adding sleep(.01) statements to a polling loop. In a way, if you execute a sleep(.01) only when you have no events in your poll you will be more efficient than if you had a blocking call pull events off your Queue one by one - because each call to Queue.get() consumes a time-slice, whereas the sleep(.01) only occurs once. </p>
Pyqt / Pyside: thread-safe callbacks + main loop integration (Python)
2013-10-12T08:43:09-07:00Justin Israelhttp://code.activestate.com/recipes/users/4187487/http://code.activestate.com/recipes/578634-pyqt-pyside-thread-safe-callbacks-main-loop-integr/
<p style="color: grey">
Python
recipe 578634
by <a href="/recipes/users/4187487/">Justin Israel</a>
(<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/pyqt/">pyqt</a>, <a href="/recipes/tags/pyside/">pyside</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/thread/">thread</a>).
Revision 4.
</p>
<p>A mechanism for communication from any thread to the main thread.</p>
<p>It uses the same custom Event, but adds a classmethod convenience for taking a callback and params, wrapping it into an event and posting it to the receiver. Also adds in support for weak method references to the callback, in case the source object gets deleted before its callback is actually called.</p>
<p>Merges forks of both:
<a href="http://code.activestate.com/recipes/81253/#c5" rel="nofollow">http://code.activestate.com/recipes/81253/#c5</a>
<a href="http://code.activestate.com/recipes/578299-pyqt-pyside-thread-safe-global-queue-main-loop-int/" rel="nofollow">http://code.activestate.com/recipes/578299-pyqt-pyside-thread-safe-global-queue-main-loop-int/</a></p>
Python: A event/signal dispatcher (Python)
2013-07-29T05:34:24-07:00Esteban Castro Borsanihttp://code.activestate.com/recipes/users/4184010/http://code.activestate.com/recipes/578307-python-a-eventsignal-dispatcher/
<p style="color: grey">
Python
recipe 578307
by <a href="/recipes/users/4184010/">Esteban Castro Borsani</a>
(<a href="/recipes/tags/dispatcher/">dispatcher</a>, <a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/oop/">oop</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/signals/">signals</a>).
</p>
<p>This is a thread-safe dispatcher.</p>
Improved Signals/Slots implementation in Python (Python)
2011-12-12T22:47:25-08:00Christopher S. Casehttp://code.activestate.com/recipes/users/4180238/http://code.activestate.com/recipes/577980-improved-signalsslots-implementation-in-python/
<p style="color: grey">
Python
recipe 577980
by <a href="/recipes/users/4180238/">Christopher S. Case</a>
(<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/qt4/">qt4</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/slot/">slot</a>).
</p>
<p>I've modified the excellent <a href="http://code.activestate.com/recipes/576477-yet-another-signalslot-implementation-in-python/"><a href="http://code.activestate.com/recipes/576477/">recipe 576477</a></a> to allow for non method functions as well as method functions. This implementation also uses a WeakKeyDictionary instead of a WeakValueDictionary for reasons of code simplification/style.</p>
Function Pipelines (Python)
2011-05-15T19:38:13-07:00Alexandre Zanihttp://code.activestate.com/recipes/users/4177180/http://code.activestate.com/recipes/577696-function-pipelines/
<p style="color: grey">
Python
recipe 577696
by <a href="/recipes/users/4177180/">Alexandre Zani</a>
(<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/wsgi/">wsgi</a>).
</p>
<p>Pipelines can be used to chain a series of functions to process a piece of data. For instance you can build a pipeline to process web requests easily including some middleware for instance.</p>
Function Pipelines (Python)
2011-05-22T20:39:05-07:00Rob Lhttp://code.activestate.com/recipes/users/4178061/http://code.activestate.com/recipes/577714-function-pipelines/
<p style="color: grey">
Python
recipe 577714
by <a href="/recipes/users/4178061/">Rob L</a>
(<a href="/recipes/tags/events/">events</a>, <a href="/recipes/tags/pipelining/">pipelining</a>, <a href="/recipes/tags/wsgi/">wsgi</a>).
</p>
<p>Alexandre Zani's recipe on function pipelines was useful. I wanted to change it to suit my needs.</p>
<p>Mostly I just wanted to add arbitrary functions and make the pipe line more list like in behavior.</p>
<p>(edit: typos)</p>