Interruptible thread join in Python

前端 未结 5 1873
暗喜
暗喜 2020-12-07 22:49

Is there any way to wait for termination of a thread, but still intercept signals?

Consider the following C program:



        
5条回答
  •  天涯浪人
    2020-12-07 23:32

    Poll on isAlive before calling join. This polling can be interrupted, of course, and once the thread isn't isAlive, join is immediate.

    An alternative would be polling on join with a timeout, checking with isAlive whether the timeout occurred. This can spend less CPU than the previous method.

提交回复
热议问题