Popular recipes tagged "signal" but not "sound"http://code.activestate.com/recipes/tags/signal-sound/2017-04-01T21:11:50-07:00ActiveState Code RecipesSimple signal library, similar to PyQT signals (Python) 2017-04-01T21:11:50-07:00Miguel Martínez Lópezhttp://code.activestate.com/recipes/users/4189907/http://code.activestate.com/recipes/580764-simple-signal-library-similar-to-pyqt-signals/ <p style="color: grey"> Python recipe 580764 by <a href="/recipes/users/4189907/">Miguel Martínez López</a> (<a href="/recipes/tags/event/">event</a>, <a href="/recipes/tags/pubsub/">pubsub</a>, <a href="/recipes/tags/signal/">signal</a>). Revision 11. </p> <p>Simple signal library similar to PyQT signals. Signals helps to decouple code in GUI applications. This code could be used in Tkinter applications for example.</p> <p>Inspired and based in these other modules:</p> <p><a href="https://github.com/shaunduncan/smokesignal" rel="nofollow">https://github.com/shaunduncan/smokesignal</a></p> <p><a href="https://github.com/dgovil/PySignal" rel="nofollow">https://github.com/dgovil/PySignal</a></p> <p><a href="https://github.com/jek/blinker" rel="nofollow">https://github.com/jek/blinker</a></p> Register exit function (Python) 2016-05-31T00:42:47-07:00Giampaolo Rodolàhttp://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/580672-register-exit-function/ <p style="color: grey"> Python recipe 580672 by <a href="/recipes/users/4178764/">Giampaolo Rodolà</a> (<a href="/recipes/tags/exit/">exit</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/signal/">signal</a>). Revision 3. </p> <p>This is a function / decorator which registers a function which will be executed on "normal" interpreter exit or in case one of the <code>signals</code> is received by this process (differently from atexit.register()). Also, it makes sure to execute any other function which was previously registered via signal.signal(). If any, it will be executed after our own <code>fun</code>. The full blogpost explaining why you should use this instead of atexit module is here: <a href="http://grodola.blogspot.com/2016/02/how-to-always-execute-exit-functions-in-py.html" rel="nofollow">http://grodola.blogspot.com/2016/02/how-to-always-execute-exit-functions-in-py.html</a></p> Discrete Fourier Transform (Python) 2014-12-27T21:43:53-08:00FB36http://code.activestate.com/recipes/users/4172570/http://code.activestate.com/recipes/578994-discrete-fourier-transform/ <p style="color: grey"> Python recipe 578994 by <a href="/recipes/users/4172570/">FB36</a> (<a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/mathematics/">mathematics</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/signal_processing/">signal_processing</a>). </p> <p>Discrete Fourier Transform and Inverse Discrete Fourier Transform</p> <p>To test, it creates an input signal using a Sine wave that has known frequency, amplitude, phase. Later it calculates DFT of the input signal and finds its frequency, amplitude, phase to compare.</p> Handle exit context manager (Python) 2014-08-01T08:28:07-07:00Giampaolo Rodolàhttp://code.activestate.com/recipes/users/4178764/http://code.activestate.com/recipes/577997-handle-exit-context-manager/ <p style="color: grey"> Python recipe 577997 by <a href="/recipes/users/4178764/">Giampaolo Rodolà</a> (<a href="/recipes/tags/atexit/">atexit</a>, <a href="/recipes/tags/contextlib/">contextlib</a>, <a href="/recipes/tags/contextmanager/">contextmanager</a>, <a href="/recipes/tags/exit/">exit</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/python3/">python3</a>, <a href="/recipes/tags/shutdown/">shutdown</a>, <a href="/recipes/tags/sigint/">sigint</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/sigterm/">sigterm</a>). Revision 23. </p> <p>A context manager which properly handles SIGTERM (SystemExit) and SIGINT (KeyboardInterrupt) signals, registering a function which is always guaranteed to be called on interpreter exit. Also, it makes sure to execute previously registered functions as well (if any).</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> 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> POSIX Semaphore (FreeBSD) (Python) 2011-04-14T17:54:16-07:00David Naylorhttp://code.activestate.com/recipes/users/4177661/http://code.activestate.com/recipes/577655-posix-semaphore-freebsd/ <p style="color: grey"> Python recipe 577655 by <a href="/recipes/users/4177661/">David Naylor</a> (<a href="/recipes/tags/ctypes/">ctypes</a>, <a href="/recipes/tags/freebsd/">freebsd</a>, <a href="/recipes/tags/semaphores/">semaphores</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/threads/">threads</a>). </p> <p>POSIX Semaphore bindings for FreeBSD. </p> Debugging a running python process by interrupting and providing an interactive prompt (Python) 2008-09-25T11:23:29-07:00Brian McErleanhttp://code.activestate.com/recipes/users/111980/http://code.activestate.com/recipes/576515-debugging-a-running-python-process-by-interrupting/ <p style="color: grey"> Python recipe 576515 by <a href="/recipes/users/111980/">Brian McErlean</a> (<a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/interactive/">interactive</a>, <a href="/recipes/tags/remote/">remote</a>, <a href="/recipes/tags/signal/">signal</a>). Revision 2. </p> <p>This provides code to allow any python program which uses it to be interrupted at the current point, and communicated with via a normal python interactive console. This allows the locals, globals and associated program state to be investigated, as well as calling arbitrary functions and classes.</p> <p>To use, a process should import the module, and call listen() at any point during startup. To interrupt this process, the script can be run directly, giving the process Id of the process to debug as the parameter.</p> pending/blocking a signal (C) 2009-05-25T22:42:30-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576775-pendingblocking-a-signal/ <p style="color: grey"> C recipe 576775 by <a href="/recipes/users/4170398/">J Y</a> (<a href="/recipes/tags/signal/">signal</a>). </p> <p><a href="http://www-h.eng.cam.ac.uk/help/tpl/unix/signals.html" rel="nofollow">http://www-h.eng.cam.ac.uk/help/tpl/unix/signals.html</a></p> <p>do you want certain signals to be ignored or blocked? The sigaction(), sigprocmask(), siginterrupt(), and sigsuspend() functions control the manipulation of the signal mask, which defines the set of signals currently blocked. The manual pages give details. The following code shows how the response to signals can be delayed. </p> sigaction on SIGCHLD (C) 2009-05-25T23:54:57-07:00J Yhttp://code.activestate.com/recipes/users/4170398/http://code.activestate.com/recipes/576776-sigaction-on-sigchld/ <p style="color: grey"> C recipe 576776 by <a href="/recipes/users/4170398/">J Y</a> (<a href="/recipes/tags/signal/">signal</a>). Revision 2. </p> <p>sigaction</p> Yet another signal/slot implementation in Python (Python) 2008-09-01T23:21:28-07:00Thiago Marcos P. Santoshttp://code.activestate.com/recipes/users/4166797/http://code.activestate.com/recipes/576477-yet-another-signalslot-implementation-in-python/ <p style="color: grey"> Python recipe 576477 by <a href="/recipes/users/4166797/">Thiago Marcos P. Santos</a> (<a href="/recipes/tags/observer/">observer</a>, <a href="/recipes/tags/publish/">publish</a>, <a href="/recipes/tags/signal/">signal</a>, <a href="/recipes/tags/slot/">slot</a>, <a href="/recipes/tags/subscribe/">subscribe</a>, <a href="/recipes/tags/weakref/">weakref</a>). </p> <p>This code snippet was based on the nice <a href="http://code.activestate.com/recipes/439356/">recipe 439356</a> made by Patrick Chasco. My implementation supports only class methods callbacks. I'm keeping the idea of use weakrefs to avoid the interpreter keep the object allocated because the signal is registered (i.e. the signal object holds a reference to callback method). IMO the usage of WeakValueDictionary made the code smaller and clear and also are maintenance-free (when the object is collect by the garbage collector the signal is automatically unregistered). </p>