1
2
3
4 """Processes, idling, and signals."""
5
6 from logging import *
7 import os, signal, time
10 """Force-kill the current process."""
11 os.kill( os.getpid(), signal.SIGKILL )
12
16 """Sleeper class. Goes to sleep forever."""
17 @classmethod
19 """
20 Calls C{time.sleep} for 100000 seconds at a time in a
21 while-true loop.
22 """
23 while True:
24 time.sleep( 100000 )
25
26
27
28 -class SigTerm( Exception ): pass
29
31 """
32 Generic signal handler that logs the received signal to the
33 "signal" logging channel (log level INFO) and then raises
34 L{SigTerm} if it was not previously raised.
35
36 @param signum: The signal's numeric value (see C{man 7 signal}).
37
38 @param frame: Ignored.
39
40 @raise SigTerm: Only once.
41 """
42 global got_signal
43 info( 'signal', 'got signal', str( signum ) )
44 if not got_signal:
45 got_signal = True
46 raise SigTerm
47
49 """
50 For each given signal, register the L{handle_signal} as its
51 handler.
52
53 @param sigs: The set of sigs to iterate over.
54 @type sigs: set
55 """
56 global got_signal
57 got_signal = False
58 for sig in sigs:
59 signal.signal( signal.SIGTERM, handle_signal )
60