Back to index

python3.2  3.2.2
Functions | Variables
intrcheck.c File Reference
#include "Python.h"
#include "pythread.h"
#include <stdio.h>
#include <string.h>
#include <signal.h>

Go to the source code of this file.

Functions

void PyErr_SetInterrupt (void)
int PyErr_CheckSignals (void)
static int checksignals_witharg (void *arg)
static void intcatcher (int sig)
void PyOS_InitInterrupts (void)
void PyOS_FiniInterrupts (void)
int PyOS_InterruptOccurred (void)
void PyOS_AfterFork (void)

Variables

static int interrupted
static void(* old_siginthandler )(int) = SIG_DFL

Function Documentation

static int checksignals_witharg ( void arg) [static]

Definition at line 115 of file intrcheck.c.

{
    return PyErr_CheckSignals();
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void intcatcher ( int  sig) [static]

Definition at line 121 of file intrcheck.c.

{
    extern void Py_Exit(int);
    static char message[] =
"python: to interrupt a truly hanging Python program, interrupt once more.\n";
    switch (interrupted++) {
    case 0:
        break;
    case 1:
        write(2, message, strlen(message));
        break;
    case 2:
        interrupted = 0;
        Py_Exit(1);
        break;
    }
    PyOS_setsig(SIGINT, intcatcher);
    Py_AddPendingCall(checksignals_witharg, NULL);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 897 of file signalmodule.c.

{
    int i;
    PyObject *f;

    if (!is_tripped)
        return 0;

#ifdef WITH_THREAD
    if (PyThread_get_thread_ident() != main_thread)
        return 0;
#endif

    /*
     * The is_tripped variable is meant to speed up the calls to
     * PyErr_CheckSignals (both directly or via pending calls) when no
     * signal has arrived. This variable is set to 1 when a signal arrives
     * and it is set to 0 here, when we know some signals arrived. This way
     * we can run the registered handlers with no signals blocked.
     *
     * NOTE: with this approach we can have a situation where is_tripped is
     *       1 but we have no more signals to handle (Handlers[i].tripped
     *       is 0 for every signal i). This won't do us any harm (except
     *       we're gonna spent some cycles for nothing). This happens when
     *       we receive a signal i after we zero is_tripped and before we
     *       check Handlers[i].tripped.
     */
    is_tripped = 0;

    if (!(f = (PyObject *)PyEval_GetFrame()))
        f = Py_None;

    for (i = 1; i < NSIG; i++) {
        if (Handlers[i].tripped) {
            PyObject *result = NULL;
            PyObject *arglist = Py_BuildValue("(iO)", i, f);
            Handlers[i].tripped = 0;

            if (arglist) {
                result = PyEval_CallObject(Handlers[i].func,
                                           arglist);
                Py_DECREF(arglist);
            }
            if (!result)
                return -1;

            Py_DECREF(result);
        }
    }

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 107 of file intrcheck.c.

{
    interrupted = 1;
}

Definition at line 168 of file intrcheck.c.

{
#ifdef WITH_THREAD
    PyEval_ReInitThreads();
    PyThread_ReInitTLS();
#endif
}

Here is the call graph for this function:

Definition at line 151 of file intrcheck.c.

Here is the call graph for this function:

Definition at line 144 of file intrcheck.c.

{
    if ((old_siginthandler = PyOS_setsig(SIGINT, SIG_IGN)) != SIG_IGN)
        PyOS_setsig(SIGINT, intcatcher);
}

Here is the call graph for this function:

Definition at line 157 of file intrcheck.c.

{
    if (!interrupted)
        return 0;
    interrupted = 0;
    return 1;
}

Variable Documentation

int interrupted [static]

Definition at line 104 of file intrcheck.c.

void(* old_siginthandler)(int) = SIG_DFL [static]

Definition at line 141 of file intrcheck.c.