comparison Python/pythonrun.c @ 16073:713ed6c6bcb5 legacy-trunk

Bug #128475: mimetools.encode (sometimes) fails when called from a thread. pythonrun.c: In Py_Finalize, don't reset the initialized flag until after the exit funcs have run. atexit.py: in _run_exitfuncs, mutate the list of pending calls in a threadsafe way. This wasn't a contributor to bug 128475, it just burned my eyeballs when looking at that bug.
author Tim Peters <tim.peters@gmail.com>
date Sun, 21 Jan 2001 03:40:37 +0000
parents cf17a3ce5387
children 8c41f3861aad
comparison
equal deleted inserted replaced
16072:bae889f44cd1 16073:713ed6c6bcb5
179 PyInterpreterState *interp; 179 PyInterpreterState *interp;
180 PyThreadState *tstate; 180 PyThreadState *tstate;
181 181
182 if (!initialized) 182 if (!initialized)
183 return; 183 return;
184
185 /* The interpreter is still entirely intact at this point, and the
186 * exit funcs may be relying on that. In particular, if some thread
187 * or exit func is still waiting to do an import, the import machinery
188 * expects Py_IsInitialized() to return true. So don't say the
189 * interpreter is uninitialized until after the exit funcs have run.
190 * Note that Threading.py uses an exit func to do a join on all the
191 * threads created thru it, so this also protects pending imports in
192 * the threads created via Threading.
193 */
194 call_sys_exitfunc();
184 initialized = 0; 195 initialized = 0;
185
186 call_sys_exitfunc();
187 196
188 /* Get current thread state and interpreter pointer */ 197 /* Get current thread state and interpreter pointer */
189 tstate = PyThreadState_Get(); 198 tstate = PyThreadState_Get();
190 interp = tstate->interp; 199 interp = tstate->interp;
191 200