Dynamically swapping between two algorithms

dieter dieter at handshake.de
Wed Sep 24 09:44:26 CEST 2014


Steven D'Aprano <steve+comp.lang.python at pearwood.info> writes:
> ...
> *If* Python was a different language, I would spawn two threads, one using
> SHORT and the other using LARGE, then which ever completes first, I'd just
> kill the other. Alas, this won't work because (1) the GIL

The GIL does not prevent this scenario. The two threads will not
really run in parallel but interleaved - but this should not be a big
problem.

> and (2) you
> cannot forcibly kill threads, only ask them to die and hope they listen.

You can kill threads (though you will need a "C" level function for this)
as long as they execute Python code.
And it is your code: you can make your threads be listening, from time to time
in the computation.




More information about the Python-list mailing list