[Python-ideas] Thread stopping

Yury Selivanov yselivanov.ml at gmail.com
Thu Mar 29 22:08:40 CEST 2012


On 2012-03-29, at 3:48 PM, Andrew Svetlov wrote:

> I propose to add Thread.interrupt() function.
> 
> th.interrupt() will set a flag in ThreadState structure.
> 
> When interpreter switches to next thread it will check that flag.
> If flag is on then ThreadInterruptionError will be raised in thread context.
> If thread has blocked via threading locks (Lock, RLock, Condition,
> Semaphore etc) — exception is raised also.

+1.

This feature would be nice for thread-pools.  For instance to
be able join a pool with a timeout.

-
Yury




More information about the Python-ideas mailing list