[Python-bugs-list] thread-killing (PR#215)

Tim Peters tim_one@email.msn.com
Sun, 27 Feb 2000 03:06:58 -0500


[zacoya@varium.com]
> I didn't see a form for feature requests, so I'm using the
> bug-report form.
>
> I'd like to see a mechanism for forcibly killing a thread.  I
> realize this is unsafe, but it has its uses.  For example, in
> project I'm working on, we run untrusted code in a separate thread.
> We'd like to be able to kill this thread if it takes too long
> to execute.

This won't happen, because Python threads are a layer on top of native
threads, and many native thread packages don't support thread killing.
Since threads at the Python level are platform-independent, Python will
never expose a thread gimmick that is (like this one) inherently
platform-dependent (there's no way for Python to "fake this" -- the native
thread pkg supports it or it doesn't).

If your particular platorm does support thread-killing, you can write some C
code to accomplish what you want, although it will probably break something.

Why not run the untrusted code in a separate *process*?  It's extremely
unwise to run *untrusted* code in your own address space anyway -- the very
things that make threads lightweight make them untrustworthy too.