Popular Python recipes tagged "meta:requires=signal"http://code.activestate.com/recipes/langs/python/tags/meta:requires=signal/2013-01-21T19:51:00-08:00ActiveState Code RecipesQueue 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>
Script para descargar videos desde http://www.chilevision.cl/ (Python)
2010-08-23T20:20:15-07:00jrovegnohttp://code.activestate.com/recipes/users/4170207/http://code.activestate.com/recipes/577367-script-para-descargar-videos-desde-httpwwwchilevis/
<p style="color: grey">
Python
recipe 577367
by <a href="/recipes/users/4170207/">jrovegno</a>
(<a href="/recipes/tags/chv/">chv</a>, <a href="/recipes/tags/download/">download</a>, <a href="/recipes/tags/tv/">tv</a>, <a href="/recipes/tags/video/">video</a>).
</p>
<p>Requiere:
- aria2c - wget
Extras:
Ofrece Descargar el resto de los videos
Uso:
# Comillas requeridas, problema parser
cvh_video.py "http://www.chilevision.cl/home/index.php?option=com_content&task=view&id=YYYYY&Itemid=XXX"</p>
Multi threaded SMTP proxy (Python)
2010-06-12T22:27:00-07:00Lobsanghttp://code.activestate.com/recipes/users/4174176/http://code.activestate.com/recipes/577260-multi-threaded-smtp-proxy/
<p style="color: grey">
Python
recipe 577260
by <a href="/recipes/users/4174176/">Lobsang</a>
(<a href="/recipes/tags/mail/">mail</a>, <a href="/recipes/tags/proxy/">proxy</a>, <a href="/recipes/tags/smtp/">smtp</a>).
Revision 2.
</p>
<p>This smtp proxy can be used to process any part of the message (header and body). It is also possible to process all the body part just before it is send to the MTA.</p>
<p>The aim of this proxy is to allow a modification of the message on the fly. It had been tested with the postfix <a href="http://www.postfix.org/SMTPD_PROXY_README.html">before queue content filter</a></p>
Asynchronous subprocess using asyncore (Python)
2013-01-21T19:51:00-08:00Glenn Eychanerhttp://code.activestate.com/recipes/users/4172294/http://code.activestate.com/recipes/576957-asynchronous-subprocess-using-asyncore/
<p style="color: grey">
Python
recipe 576957
by <a href="/recipes/users/4172294/">Glenn Eychaner</a>
(<a href="/recipes/tags/async/">async</a>, <a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/asyncore/">asyncore</a>, <a href="/recipes/tags/coroutine/">coroutine</a>, <a href="/recipes/tags/decorator/">decorator</a>, <a href="/recipes/tags/generator/">generator</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 21.
</p>
<p>A coroutine-based wrapper for subprocess.Popen that uses asyncore to communicate with child processes asynchronously. This allows subprocesses to be called from within socket servers or clients without needing a complicated event loop to check both. Uses <a href="http://code.activestate.com/recipes/576965/">recipe 576965</a> to provide the asynchronous coroutine framework, <a href="http://code.activestate.com/recipes/576967/">recipe 576967</a> to provide asynchronous pipes, and <a href="http://code.activestate.com/recipes/577600/">recipe 577600</a> to provide multiple alarms.</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>
Subprocess with async I/O pipes class (Python)
2009-05-17T02:02:04-07:00Mike Kazantsevhttp://code.activestate.com/recipes/users/4170279/http://code.activestate.com/recipes/576759-subprocess-with-async-io-pipes-class/
<p style="color: grey">
Python
recipe 576759
by <a href="/recipes/users/4170279/">Mike Kazantsev</a>
(<a href="/recipes/tags/asynchronous/">asynchronous</a>, <a href="/recipes/tags/ipc/">ipc</a>, <a href="/recipes/tags/non_blocking_i_o/">non_blocking_i_o</a>, <a href="/recipes/tags/pipe/">pipe</a>, <a href="/recipes/tags/subprocess/">subprocess</a>).
Revision 2.
</p>
<p>Just stumbled upon the need to move data chunks between subprocesses in a non-linear way with some logic in-between, so tee(1) and fifo(7)'s weren't too good option.
Inspired by 440554, but rewritten from scratch to remove unnecessary delays due to sleep(3) calls and suboptimal try/sleep-based polling.</p>
Chat server & client using select.select (Python)
2007-09-28T08:57:53-07:00Anandhttp://code.activestate.com/recipes/users/760763/http://code.activestate.com/recipes/531824-chat-server-client-using-selectselect/
<p style="color: grey">
Python
recipe 531824
by <a href="/recipes/users/760763/">Anand</a>
(<a href="/recipes/tags/network/">network</a>).
Revision 3.
</p>
<p>This recipe demos how to write a simple command line chat server & client using multiplexing using select.select. The server uses select call to multiplex multiple clients and the client uses it to multiplex command line & socket I/O.</p>
subprocess.terminate() not always implemented (Python)
2009-02-25T10:45:01-08:00Gui Rhttp://code.activestate.com/recipes/users/4166241/http://code.activestate.com/recipes/576667-subprocessterminate-not-always-implemented/
<p style="color: grey">
Python
recipe 576667
by <a href="/recipes/users/4166241/">Gui R</a>
(<a href="/recipes/tags/process_management/">process_management</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/terminate/">terminate</a>).
Revision 2.
</p>
<p>The new subprocess module brings clarity and simplicity over the popenXX() functions and os.spawnXX() functions, but some implementations don't have the subprocess.terminate() method, which is crucial for killing a spawned process. This workaround works on both POSIX and Windows.</p>
Sensible Loop Status (Python)
2008-10-05T02:14:52-07:00David Lamberthttp://code.activestate.com/recipes/users/4167420/http://code.activestate.com/recipes/576528-sensible-loop-status/
<p style="color: grey">
Python
recipe 576528
by <a href="/recipes/users/4167420/">David Lambert</a>
(<a href="/recipes/tags/debug/">debug</a>, <a href="/recipes/tags/debugging/">debugging</a>, <a href="/recipes/tags/logging/">logging</a>, <a href="/recipes/tags/progress/">progress</a>, <a href="/recipes/tags/status/">status</a>).
</p>
<p>A LoopStatus object tests true according to geometric progression or time intervals. This enables rapid time estimates for long running codes, typically in a loop, without producing copious highly repetitive output.</p>
Timing an external subprocess (Python)
2008-09-24T11:34:52-07:00Benjamin Hallhttp://code.activestate.com/recipes/users/4167286/http://code.activestate.com/recipes/576514-timing-an-external-subprocess/
<p style="color: grey">
Python
recipe 576514
by <a href="/recipes/users/4167286/">Benjamin Hall</a>
(<a href="/recipes/tags/running_external_programs/">running_external_programs</a>, <a href="/recipes/tags/subprocesses/">subprocesses</a>).
</p>
<p>Running separate processes with os.system() has a single major disadvantage for the work I'm doing, and that is the external program is prone to entering a state where it stops producing any output. The "wallclock" subroutine runs an external command and periodically checks to see if it has finished, killing it if it runs for too long.</p>
unix subprocess wrapper (Python)
2008-07-29T07:11:17-07:00Pádraig Bradyhttp://code.activestate.com/recipes/users/1890175/http://code.activestate.com/recipes/576387-unix-subprocess-wrapper/
<p style="color: grey">
Python
recipe 576387
by <a href="/recipes/users/1890175/">Pádraig Brady</a>
(<a href="/recipes/tags/group/">group</a>, <a href="/recipes/tags/popen/">popen</a>, <a href="/recipes/tags/subprocess/">subprocess</a>, <a href="/recipes/tags/unix/">unix</a>).
Revision 2.
</p>
<p>I have used this for ages to control child processes (and all their children). Some of the existing subprocess module was based on this, but I find this simpler for my uses at least.</p>
<h4>Example:</h4>
<pre class="prettyprint"><code>import subProcess
process = subProcess.subProcess("your shell command")
process.read() #timeout is optional
handle(process.outdata, process.errdata)
del(process)
</code></pre>
Function Timeout (Python)
2007-10-19T22:33:18-07:00Symon Polleyhttp://code.activestate.com/recipes/users/4056524/http://code.activestate.com/recipes/534115-function-timeout/
<p style="color: grey">
Python
recipe 534115
by <a href="/recipes/users/4056524/">Symon Polley</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>).
Revision 2.
</p>
<p>a simple and useful script that uses signal to time out any function.</p>
<p>EDIT: use Jim Carrolls solution below</p>
Cleaning up when killed (Python)
2007-09-27T10:33:56-07:00Miki Tebekahttp://code.activestate.com/recipes/users/4086267/http://code.activestate.com/recipes/533117-cleaning-up-when-killed/
<p style="color: grey">
Python
recipe 533117
by <a href="/recipes/users/4086267/">Miki Tebeka</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>atexit handlers are not called when a process is killed, this recipe show how to fix that.</p>
Workaround for missed SIGINT in multithreaded programs (Python)
2006-05-24T09:19:44-07:00Allen Downeyhttp://code.activestate.com/recipes/users/2523263/http://code.activestate.com/recipes/496735-workaround-for-missed-sigint-in-multithreaded-prog/
<p style="color: grey">
Python
recipe 496735
by <a href="/recipes/users/2523263/">Allen Downey</a>
(<a href="/recipes/tags/sysadmin/">sysadmin</a>).
</p>
<p>Multithreaded Python programs often ignore the SIGINT generated by a
Keyboard Interrupt, especially if the thread that gets the signal is
waiting or sleeping. This module provides a workaround by forking a
child process that executes the rest of the program while the parent
process waits for signals and kills the child process.</p>
Signal Handler Decorator (Python)
2005-04-21T18:15:06-07:00Doug Forthttp://code.activestate.com/recipes/users/118211/http://code.activestate.com/recipes/410666-signal-handler-decorator/
<p style="color: grey">
Python
recipe 410666
by <a href="/recipes/users/118211/">Doug Fort</a>
.
</p>
<p>This decorator simply sets the function as the signal handler for the signal given as its argument.</p>
Timing out function (Python)
2004-10-14T11:55:55-07:00chris wrighthttp://code.activestate.com/recipes/users/2032785/http://code.activestate.com/recipes/307871-timing-out-function/
<p style="color: grey">
Python
recipe 307871
by <a href="/recipes/users/2032785/">chris wright</a>
.
Revision 3.
</p>
<p>This recipe presents two ways to time out the execution of a callable. It relies on signal.SIGALRM; I've only tested in on MacOSX. One way (TimedOutFn) works on Python 2.3.4, and the second uses the decorator syntax introduced in 2.4a. In this version, I've used the code from John Speno's page (<a href="http://www.pycs.net/users/0000231/" rel="nofollow">http://www.pycs.net/users/0000231/</a>). He's done a better job of handling the signals, and I like the try/finally expression.</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>
Remote database access using XML-RPC and SOAP. (Python)
2001-11-01T00:42:22-08:00Graham Dumpletonhttp://code.activestate.com/recipes/users/135831/http://code.activestate.com/recipes/81613-remote-database-access-using-xml-rpc-and-soap/
<p style="color: grey">
Python
recipe 81613
by <a href="/recipes/users/135831/">Graham Dumpleton</a>
(<a href="/recipes/tags/database/">database</a>).
Revision 3.
</p>
<p>Shows how to remotely access a database via a web service supporting XML-RPC and SOAP protocols. The example uses the MySQLdb module, but should be easily customised to any database with Python module adhering to the Python DB API. The web service interface provides the ability to make a self contained query, or allows the creation of a distinct database cursor to service a series of queries or updates without other clients interfering. Cursors automatically expire and delete themselves after a set period of inactivity if not explicitly closed.</p>
Web service accessible using both XML-RPC and SOAP protocols. (Python)
2001-11-01T00:48:32-08:00Graham Dumpletonhttp://code.activestate.com/recipes/users/135831/http://code.activestate.com/recipes/81612-web-service-accessible-using-both-xml-rpc-and-soap/
<p style="color: grey">
Python
recipe 81612
by <a href="/recipes/users/135831/">Graham Dumpleton</a>
(<a href="/recipes/tags/web/">web</a>).
Revision 3.
</p>
<p>This is yet another example of an XML-RPC capable web service. Where this example is different though, is that the service can be accessed at the same time using the SOAP protocol. Confusion is avoided by clients for each protocol using different URLs to access the service.</p>
Distributed request/reply middleware architecture. (Python)
2001-10-14T01:39:22-07:00Graham Dumpletonhttp://code.activestate.com/recipes/users/135831/http://code.activestate.com/recipes/81615-distributed-requestreply-middleware-architecture/
<p style="color: grey">
Python
recipe 81615
by <a href="/recipes/users/135831/">Graham Dumpleton</a>
(<a href="/recipes/tags/distributed/">distributed</a>).
</p>
<p>Simple example of setting up a distributed message oriented request/reply architecture. Shows creation of a central exchange service which all participating processes connect to. Services assign themselves a name and export the methods which are remotely accessible. Client services are then able to make calls against the exported methods.</p>