scrapy / scrapy
1 7
import signal
2

3

4 7
signal_names = {}
5 7
for signame in dir(signal):
6 7
    if signame.startswith('SIG') and not signame.startswith('SIG_'):
7 7
        signum = getattr(signal, signame)
8 7
        if isinstance(signum, int):
9 7
            signal_names[signum] = signame
10

11

12 7
def install_shutdown_handlers(function, override_sigint=True):
13
    """Install the given function as a signal handler for all common shutdown
14
    signals (such as SIGINT, SIGTERM, etc). If override_sigint is ``False`` the
15
    SIGINT handler won't be install if there is already a handler in place
16
    (e.g.  Pdb)
17
    """
18 7
    from twisted.internet import reactor
19 7
    reactor._handleSignals()
20 7
    signal.signal(signal.SIGTERM, function)
21 7
    if signal.getsignal(signal.SIGINT) == signal.default_int_handler or override_sigint:
22 7
        signal.signal(signal.SIGINT, function)
23
    # Catch Ctrl-Break in windows
24 7
    if hasattr(signal, 'SIGBREAK'):
25 0
        signal.signal(signal.SIGBREAK, function)

Read our documentation on viewing source code .

Loading