I came across some interesting articles on the subject of killing child threads from a main process. I had only done this before in C# .NET, so I assumed this was a regular feature of threads, but then I discovered that Python has no built-in way of doing this. Java used to, but the methods are deprecated now. Considering all this, I find it interesting that Microsoft allows you to do it anyway (not that Microsoft is exactly known for doing things The Right Way™)!
So the recommended way to kill a child thread is through the use of a boolean variable within the child thread instance itself. The thread should poll this variable regularly within its “run” method to determine whether or not the thread should stop itself.
That’s simple enough. Unfortunately, I find this to be an inadequate solution when dealing with blocking I/O calls, since you still have to wait for the function to return. I wonder how people get around things like this when writing GUI apps, which generally need to be responsive at all times…
Update: I have now discovered wx.lib.delayedresult. However, I have also discovered the hard way that widgets should never be updated by worker threads. Doing so results in strange errors and segfaults in GTK.