Peter Hansen wrote: > [EMAIL PROTECTED] wrote: > >> Nevermind. I found a better solution. I used shared memory to create >> a keep-alive flag. I then use the select function with a specified >> timeout, and recheck the keep-alive flag after each timeout. > > > As Dennis points out, your original attempt was destined to fail because > you were calling the method from the main thread, not the one you wanted <snip>
A similar problem exists in .NET but they "solved" it by creating an Abort method that raises an exception in the thread itself, basically doing what you wanted to do. However, this leads to all sorts of problem, particular when that exception is raised in a finally block in that thread, which could mean that the finally block did not fully execute, leading to resource leaks or similar problems. They pondered a while about constructing non-interruptible blocks of code for .NET 2.0 but I'm not entirely sure how that worked out. In any case, the best way is to use some kind of signal that the thread reacts to, either by having it specifically wait for a signallable object (like an event) or just by checking a boolean variable or similar for a magic value that means "now is a good time for you to terminate". -- Lasse Vågsæther Karlsen http://usinglvkblog.blogspot.com/ mailto:[EMAIL PROTECTED] PGP KeyID: 0x2A42A1C2 -- http://mail.python.org/mailman/listinfo/python-list