[Python-Dev] Interrupting a thread

Gordon McMillan gmcm at hypernet.com
Wed Jul 14 09:40:41 EDT 1999


[Mark wants to interrupt threads]

[Tim arrives with a bucket of cold water]
> > I don't think there's any portable way to do this.  Even
> > restricting the
> > scope to Windows, forget Python for a moment:  can you do
> > this reliably with
> > NT threads from C, availing yourself of every trick in the
> > SDK?  Not that I

[Mark is stubborn...] 
> Nope - not if I forget Python.  However, when I restrict myself _to_
> Python, I find this nice little ceval.c loop and nice little
> per-thread structures - even with nice-looking exception
> place-holders ;-)

[The iceman cometh...]
If you'd like your app to remain usable, you'd have to be certain that
this thread held no locks of any kind. If it did, it is likely that
said lock could never be released even if you found it!

If the thread is doing something, there are certainly places where you
can insert a "time to quit?" check. If it's hopelessly blocked, you
can ignore it or even cut it off from interacting with the rest of the
app. It'll consume some memory but no CPU and die when the OS cleans
up at the end of the process.

Note that the latter case (of hopelessly blocked) wouldn't be helped
by evil manipulations of his Python state.


- Gordon




More information about the Python-list mailing list