Charles-François Natali added the comment:

And here's a patch.

----------
keywords: +patch
Added file: http://bugs.python.org/file29244/thread_local_concurrent.diff

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue17263>
_______________________________________
--- Python-3.3.0/Modules/_threadmodule.c        2013-02-26 08:37:05.000000000 
+0000
+++ python/Modules/_threadmodule.c      2013-02-26 08:48:24.000000000 +0000
@@ -769,6 +769,7 @@
 local_clear(localobject *self)
 {
     PyThreadState *tstate;
+    PyInterpreterState *interp;
     Py_CLEAR(self->args);
     Py_CLEAR(self->kw);
     Py_CLEAR(self->dummies);
@@ -776,13 +777,18 @@
     /* Remove all strong references to dummies from the thread states */
     if (self->key
         && (tstate = PyThreadState_Get())
-        && tstate->interp) {
-        for(tstate = PyInterpreterState_ThreadHead(tstate->interp);
-            tstate;
-            tstate = PyThreadState_Next(tstate)) {
+        && (interp = tstate->interp)) {
+        for (tstate = PyInterpreterState_ThreadHead(interp);
+             tstate;) {
             if (tstate->dict &&
-                PyDict_GetItem(tstate->dict, self->key))
+                PyDict_GetItem(tstate->dict, self->key)) {
                 PyDict_DelItem(tstate->dict, self->key);
+                /* the list of threads could have been altered, restart from
+                 * the head */
+                tstate = PyInterpreterState_ThreadHead(interp);
+            } else {
+                tstate = PyThreadState_Next(tstate);
+            }
         }
     }
     return 0;
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to