关于python中中断一个线程的问题
由于一些任务是长时间任务,并不是循环调度的任务,所以设置一个Flag用于判断是否退出线程,虽然安全但是不太方便。
在Thread的_stop()方法的说明是这样的:
···
#After calling ._stop(), .is_alive() returns False and .join() returns
# immediately. ._tstate_lock must be released before calling ._stop().
#
# Normal case: C code at the end of the thread’s life
# (release_sentinel in _threadmodule.c) releases ._tstate_lock, and
# that’s detected by our ._wait_for_tstate_lock(), called by .join()
# and .is_alive(). Any number of threads may call ._stop()
# simultaneously (for example, if multiple threads are blocked in
# .join() calls), and they’re not serialized. That’s harmless -
# they’ll just make redundant rebindings of ._is_stopped and
# ._tstate_lock. Obscure: we rebind ._tstate_lock last so that the
# “assert self._is_stopped” in ._wait_for_tstate_lock() always works
# (the asser