@@ -189,12 +189,13 @@ tasklet_clear(PyTaskletObject *t)
189
189
Py_CLEAR (t -> exc_state .exc_value );
190
190
Py_CLEAR (t -> exc_state .exc_traceback );
191
191
192
- /* The stack of exception states should contain just this tasklet. */
193
- assert (t -> exc_info -> previous_item == NULL );
194
- if (Py_VerboseFlag && t -> exc_info != & t -> exc_state ) {
195
- fprintf (stderr ,
196
- "PyTaskletObject_Clear: warning: tasklet still has a generator\n" );
197
- }
192
+ /* Assert that the tasklet is at the end of the chain. */
193
+ assert (t -> exc_state .previous_item == NULL );
194
+ /* Unlink the exc_info chain. There is no guarantee, that
195
+ * the object t->exc_info points to still exists, because
196
+ * the order of calls to tp_clear is undefined.
197
+ */
198
+ t -> exc_info = & t -> exc_state ;
198
199
}
199
200
200
201
/*
@@ -281,8 +282,13 @@ tasklet_dealloc(PyTaskletObject *t)
281
282
}
282
283
Py_DECREF (t -> tempval );
283
284
Py_XDECREF (t -> def_globals );
285
+ /* Assert that the tasklet is at the end of the chain. */
284
286
assert (t -> exc_state .previous_item == NULL );
285
- assert (t -> exc_info == & t -> exc_state );
287
+ /* Unlink the exc_info chain. There is no guarantee, that
288
+ * the object t->exc_info points to still exists, because
289
+ * the order of calls to tp_clear is undefined.
290
+ */
291
+ t -> exc_info = & t -> exc_state ;
286
292
exc_state_clear (& t -> exc_state );
287
293
Py_TYPE (t )-> tp_free ((PyObject * )t );
288
294
}
0 commit comments