[Python-Dev] Status of thread cancellation

Jean-Paul Calderone exarkun at divmod.com
Thu Mar 15 16:12:36 CET 2007

On Thu, 15 Mar 2007 09:41:31 -0500, skip at pobox.com wrote:
>    >> I just proposed to implement thread cancellation for the SoC.  Is
>    >> there any prior work where one could start?
>    Jean-Paul> The outcome of some prior work, at least:
>    Jean-Paul>   http://java.sun.com/j2se/1.4.2/docs/guide/misc/threadPrimitiveDeprecation.html
>I responded to that.  I got the impression reading that page that the killed
>thread doesn't regain control so it can't clean up its potentially
>inconsistent data structures.

The second question on the page:

  Couldn't I just catch the ThreadDeath exception and fix the damaged object?

Addresses this.

>I inferred from Martin's proposal that he
>expected the thread to be able to catch the exception.  Perhaps he can
>elaborate on what cleanup actions the dying thread will be allowed to

Perhaps he can.  Hopefully, he can specifically address these points:

   1. A thread can throw a ThreadDeath exception almost anywhere. All
      synchronized methods and blocks would have to be studied in great
      detail, with this in mind.

   2. A thread can throw a second ThreadDeath exception while cleaning up
      from the first (in the catch or finally clause). Cleanup would have
      to repeated till it succeeded. The code to ensure this would be quite


More information about the Python-Dev mailing list