diff -r b59f021a71c7 Include/pydebug.h --- a/Include/pydebug.h Thu Nov 08 11:19:55 2012 +0100 +++ b/Include/pydebug.h Thu Nov 08 14:55:41 2012 +0100 @@ -12,6 +12,7 @@ PyAPI_DATA(int) Py_InspectFlag; PyAPI_DATA(int) Py_OptimizeFlag; PyAPI_DATA(int) Py_NoSiteFlag; +PyAPI_DATA(int) Py_InitSigsLate; PyAPI_DATA(int) Py_BytesWarningFlag; PyAPI_DATA(int) Py_UseClassExceptionsFlag; PyAPI_DATA(int) Py_FrozenFlag; diff -r b59f021a71c7 Modules/main.c --- a/Modules/main.c Thu Nov 08 11:19:55 2012 +0100 +++ b/Modules/main.c Thu Nov 08 14:55:41 2012 +0100 @@ -43,7 +43,7 @@ static int orig_argc; /* command line options */ -#define BASE_OPTS L"bBc:dEhiJm:OqRsStuvVW:xX:?" +#define BASE_OPTS L"bBc:dEhiJm:OqRsStuvVW:xX:z?" #define PROGRAM_OPTS BASE_OPTS @@ -84,6 +84,7 @@ -X opt : set implementation-specific option\n\ "; static char *usage_4 = "\ +-z : initialise signals after 'import site'\n\ file : program read from script file\n\ - : program read from stdin (default; interactive mode if a tty)\n\ arg ...: arguments passed to program in sys.argv[1:]\n\n\ @@ -431,6 +432,10 @@ skipfirstline = 1; break; + case 'z': + Py_InitSigsLate++; + break; + case 'h': case '?': help++; diff -r b59f021a71c7 Python/pythonrun.c --- a/Python/pythonrun.c Thu Nov 08 11:19:55 2012 +0100 +++ b/Python/pythonrun.c Thu Nov 08 14:55:41 2012 +0100 @@ -85,6 +85,7 @@ int Py_InteractiveFlag; /* Needed by Py_FdIsInteractive() below */ int Py_InspectFlag; /* Needed to determine whether to exit at SystemExit */ int Py_NoSiteFlag; /* Suppress 'import site' */ +int Py_InitSigsLate; /* Initialise signal handling after 'import site' */ int Py_BytesWarningFlag; /* Warn on str(bytes) and str(buffer) */ int Py_DontWriteBytecodeFlag; /* Suppress writing bytecode files (*.py[co]) */ int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c: deprecated */ @@ -373,7 +374,7 @@ if (initfsencoding(interp) < 0) Py_FatalError("Py_Initialize: unable to load the file system codec"); - if (install_sigs) + if (install_sigs && !Py_InitSigsLate) initsigs(); /* Signal handling stuff, including initintr() */ initmain(interp); /* Module __main__ */ @@ -393,6 +394,9 @@ if (!Py_NoSiteFlag) initsite(); /* Module site */ + + if (install_sigs && Py_InitSigsLate) + initsigs(); /* Signal handling stuff, including initintr() */ } void