Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 6600:83ccf44bf195 legacy-trunk
Two changes (here we go again :-( ).
1) The __builtins__ variable in the __main__ module is set to the
__builtin__ module instead of its __dict__.
2) Get rid of the SIGHUP and SIGTERM handlers. They can't be made to
work reliably when threads may be in use, they are Unix specific, and
Python programmers can now program this functionality is a safer way
using the signal module.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 19 Nov 1997 16:15:37 +0000 |
| parents | b331cd47e0bc |
| children | 99955b65408d |
comparison
equal
deleted
inserted
replaced
| 6599:6d6fec2eeef6 | 6600:83ccf44bf195 |
|---|---|
| 371 m = PyImport_AddModule("__main__"); | 371 m = PyImport_AddModule("__main__"); |
| 372 if (m == NULL) | 372 if (m == NULL) |
| 373 Py_FatalError("can't create __main__ module"); | 373 Py_FatalError("can't create __main__ module"); |
| 374 d = PyModule_GetDict(m); | 374 d = PyModule_GetDict(m); |
| 375 if (PyDict_GetItemString(d, "__builtins__") == NULL) { | 375 if (PyDict_GetItemString(d, "__builtins__") == NULL) { |
| 376 if (PyDict_SetItemString(d, "__builtins__", | 376 PyObject *bimod = PyImport_ImportModule("__builtin__"); |
| 377 PyEval_GetBuiltins())) | 377 if (bimod == NULL || |
| 378 PyDict_SetItemString(d, "__builtins__", bimod) != 0) | |
| 378 Py_FatalError("can't add __builtins__ to __main__"); | 379 Py_FatalError("can't add __builtins__ to __main__"); |
| 379 } | 380 } |
| 380 } | 381 } |
| 381 | 382 |
| 382 /* Import the site module (not into __main__ though) */ | 383 /* Import the site module (not into __main__ though) */ |
| 1058 #else | 1059 #else |
| 1059 exit(sts); | 1060 exit(sts); |
| 1060 #endif | 1061 #endif |
| 1061 } | 1062 } |
| 1062 | 1063 |
| 1063 #ifdef HAVE_SIGNAL_H | |
| 1064 static RETSIGTYPE | |
| 1065 sighandler(sig) | |
| 1066 int sig; | |
| 1067 { | |
| 1068 signal(sig, SIG_DFL); /* Don't catch recursive signals */ | |
| 1069 /* Do essential exit processing only */ | |
| 1070 call_sys_exitfunc(); | |
| 1071 call_ll_exitfuncs(); | |
| 1072 #ifdef HAVE_KILL | |
| 1073 kill(getpid(), sig); /* Pretend the signal killed us */ | |
| 1074 #else | |
| 1075 exit(1); | |
| 1076 #endif | |
| 1077 /*NOTREACHED*/ | |
| 1078 } | |
| 1079 #endif | |
| 1080 | |
| 1081 static void | 1064 static void |
| 1082 initsigs() | 1065 initsigs() |
| 1083 { | 1066 { |
| 1084 RETSIGTYPE (*t)(); | |
| 1085 #ifdef HAVE_SIGNAL_H | 1067 #ifdef HAVE_SIGNAL_H |
| 1086 #ifdef SIGPIPE | 1068 #ifdef SIGPIPE |
| 1087 signal(SIGPIPE, SIG_IGN); | 1069 signal(SIGPIPE, SIG_IGN); |
| 1088 #endif | |
| 1089 #ifdef SIGHUP | |
| 1090 t = signal(SIGHUP, SIG_IGN); | |
| 1091 if (t == SIG_DFL) | |
| 1092 signal(SIGHUP, sighandler); | |
| 1093 else | |
| 1094 signal(SIGHUP, t); | |
| 1095 #endif | |
| 1096 #ifdef SIGTERM | |
| 1097 t = signal(SIGTERM, SIG_IGN); | |
| 1098 if (t == SIG_DFL) | |
| 1099 signal(SIGTERM, sighandler); | |
| 1100 else | |
| 1101 signal(SIGTERM, t); | |
| 1102 #endif | 1070 #endif |
| 1103 #endif /* HAVE_SIGNAL_H */ | 1071 #endif /* HAVE_SIGNAL_H */ |
| 1104 PyOS_InitInterrupts(); /* May imply initsignal() */ | 1072 PyOS_InitInterrupts(); /* May imply initsignal() */ |
| 1105 } | 1073 } |
| 1106 | 1074 |
