Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 59499:4468666d01c4 legacy-trunk
Issue #3137: Don't ignore errors at startup, especially a keyboard interrupt
(SIGINT). If an error occurs while importing the site module, the error is
printed and Python exits. Initialize the GIL before importing the site
module.
| author | Victor Stinner <victor.stinner@haypocalc.com> |
|---|---|
| date | Wed, 10 Mar 2010 22:30:19 +0000 |
| parents | 12079c3d4b77 |
| children | 95c400b9d74c |
comparison
equal
deleted
inserted
replaced
| 59493:6d9be1a97c17 | 59499:4468666d01c4 |
|---|---|
| 246 PyErr_Clear(); | 246 PyErr_Clear(); |
| 247 Py_XDECREF(warnings_module); | 247 Py_XDECREF(warnings_module); |
| 248 } | 248 } |
| 249 | 249 |
| 250 initmain(); /* Module __main__ */ | 250 initmain(); /* Module __main__ */ |
| 251 if (!Py_NoSiteFlag) | |
| 252 initsite(); /* Module site */ | |
| 253 | 251 |
| 254 /* auto-thread-state API, if available */ | 252 /* auto-thread-state API, if available */ |
| 255 #ifdef WITH_THREAD | 253 #ifdef WITH_THREAD |
| 256 _PyGILState_Init(interp, tstate); | 254 _PyGILState_Init(interp, tstate); |
| 257 #endif /* WITH_THREAD */ | 255 #endif /* WITH_THREAD */ |
| 256 | |
| 257 if (!Py_NoSiteFlag) | |
| 258 initsite(); /* Module site */ | |
| 258 | 259 |
| 259 if ((p = Py_GETENV("PYTHONIOENCODING")) && *p != '\0') { | 260 if ((p = Py_GETENV("PYTHONIOENCODING")) && *p != '\0') { |
| 260 p = icodeset = codeset = strdup(p); | 261 p = icodeset = codeset = strdup(p); |
| 261 free_codeset = 1; | 262 free_codeset = 1; |
| 262 errors = strchr(p, ':'); | 263 errors = strchr(p, ':'); |
| 282 PyObject *enc = PyCodec_Encoder(loc_codeset); | 283 PyObject *enc = PyCodec_Encoder(loc_codeset); |
| 283 if (enc) { | 284 if (enc) { |
| 284 loc_codeset = strdup(loc_codeset); | 285 loc_codeset = strdup(loc_codeset); |
| 285 Py_DECREF(enc); | 286 Py_DECREF(enc); |
| 286 } else { | 287 } else { |
| 287 loc_codeset = NULL; | 288 if (PyErr_ExceptionMatches(PyExc_LookupError)) { |
| 288 PyErr_Clear(); | 289 PyErr_Clear(); |
| 290 loc_codeset = NULL; | |
| 291 } else { | |
| 292 PyErr_Print(); | |
| 293 exit(1); | |
| 294 } | |
| 289 } | 295 } |
| 290 } else | 296 } else |
| 291 loc_codeset = NULL; | 297 loc_codeset = NULL; |
| 292 setlocale(LC_CTYPE, saved_locale); | 298 setlocale(LC_CTYPE, saved_locale); |
| 293 free(saved_locale); | 299 free(saved_locale); |
| 702 /* Import the site module (not into __main__ though) */ | 708 /* Import the site module (not into __main__ though) */ |
| 703 | 709 |
| 704 static void | 710 static void |
| 705 initsite(void) | 711 initsite(void) |
| 706 { | 712 { |
| 707 PyObject *m, *f; | 713 PyObject *m; |
| 708 m = PyImport_ImportModule("site"); | 714 m = PyImport_ImportModule("site"); |
| 709 if (m == NULL) { | 715 if (m == NULL) { |
| 710 f = PySys_GetObject("stderr"); | 716 PyErr_Print(); |
| 711 if (Py_VerboseFlag) { | 717 Py_Finalize(); |
| 712 PyFile_WriteString( | 718 exit(1); |
| 713 "'import site' failed; traceback:\n", f); | |
| 714 PyErr_Print(); | |
| 715 } | |
| 716 else { | |
| 717 PyFile_WriteString( | |
| 718 "'import site' failed; use -v for traceback\n", f); | |
| 719 PyErr_Clear(); | |
| 720 } | |
| 721 } | 719 } |
| 722 else { | 720 else { |
| 723 Py_DECREF(m); | 721 Py_DECREF(m); |
| 724 } | 722 } |
| 725 } | 723 } |
| 1544 PyObject *v, *w, *errtype; | 1542 PyObject *v, *w, *errtype; |
| 1545 PyObject* u = NULL; | 1543 PyObject* u = NULL; |
| 1546 char *msg = NULL; | 1544 char *msg = NULL; |
| 1547 errtype = PyExc_SyntaxError; | 1545 errtype = PyExc_SyntaxError; |
| 1548 switch (err->error) { | 1546 switch (err->error) { |
| 1547 case E_ERROR: | |
| 1548 return; | |
| 1549 case E_SYNTAX: | 1549 case E_SYNTAX: |
| 1550 errtype = PyExc_IndentationError; | 1550 errtype = PyExc_IndentationError; |
| 1551 if (err->expected == INDENT) | 1551 if (err->expected == INDENT) |
| 1552 msg = "expected an indented block"; | 1552 msg = "expected an indented block"; |
| 1553 else if (err->token == INDENT) | 1553 else if (err->token == INDENT) |
