Josiah Carlson wrote: > Greg Ewing <[EMAIL PROTECTED]> wrote: >> [EMAIL PROTECTED] wrote: >> >>> Can you suggest any use-cases for thread termination which will *not* >>> result in a completely broken and unpredictable heap after the thread >>> has died? >> Suppose you have a GUI and you want to launch a >> long-running computation without blocking the >> user interface. You don't know how long it will >> take, so you want the user to be able to cancel >> it if he gets bored. > > If the code is in Python, you can use sys.settrace to handle this. If > the code is in an extension module that a user has control over, having > a cancel_thread() function that is made available to Python, and having > your C code check the value of a single variable every few seconds could > do the same thing (even checking the value in a tight loop shouldn't > slow computations down significantly, branch prediction should be able > to make it a more or less zero-cost operation). Yes, it can be tedious, > but at least the programmer can actually control cleanup in a reasonable > manner.
Option 3, farm the long running operation out to another process and use the OS-provided facilities to abort and cleanup if the user changes their mind. It's the only way to be sure the aborted operation doesn't leave the main process in a dodgy state. Cheers, Nick. -- Nick Coghlan | [EMAIL PROTECTED] | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com