[Python-checkins] CVS: python/dist/src/Python pythonrun.c,2.118,2.119
Tim Peters
tim_one@users.sourceforge.net
Sat, 20 Jan 2001 19:40:39 -0800
Update of /cvsroot/python/python/dist/src/Python
In directory usw-pr-cvs1:/tmp/cvs-serv15905/python/dist/src/Python
Modified Files:
pythonrun.c
Log Message:
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.
Index: pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.118
retrieving revision 2.119
diff -C2 -r2.118 -r2.119
*** pythonrun.c 2001/01/17 21:27:36 2.118
--- pythonrun.c 2001/01/21 03:40:37 2.119
***************
*** 182,188 ****
if (!initialized)
return;
- initialized = 0;
call_sys_exitfunc();
/* Get current thread state and interpreter pointer */
--- 182,197 ----
if (!initialized)
return;
+ /* The interpreter is still entirely intact at this point, and the
+ * exit funcs may be relying on that. In particular, if some thread
+ * or exit func is still waiting to do an import, the import machinery
+ * expects Py_IsInitialized() to return true. So don't say the
+ * interpreter is uninitialized until after the exit funcs have run.
+ * Note that Threading.py uses an exit func to do a join on all the
+ * threads created thru it, so this also protects pending imports in
+ * the threads created via Threading.
+ */
call_sys_exitfunc();
+ initialized = 0;
/* Get current thread state and interpreter pointer */