Killing a thread

Gordon McMillan gmcm at hypernet.com
Mon Jul 19 09:23:37 EDT 1999


Chris (catlee at my-deja.com) writes
> 
> I'm writing a progrma where some user code is executed in a
> restricted environment running in a separate thread.  Now, if the
> user is malicious, s/he can just put 'while 1: 1+1'.  I'd like to be
> able to recover from this.  Is there any way I can kill the thread
> that is stuck in the infinite loop?

Python uses OS threads. An OS thread is a "lightweight" process. Much 
of the savings in weight is because the OS does not clean up after 
the thread (closing files, releasing locks...). So the general advice 
is that threads should never be killed from outside.

- Gordon




More information about the Python-list mailing list