本文整理汇总了Python中threading.Thread.alive方法的典型用法代码示例。如果您正苦于以下问题:Python Thread.alive方法的具体用法?Python Thread.alive怎么用?Python Thread.alive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类threading.Thread
的用法示例。
在下文中一共展示了Thread.alive方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from threading import Thread [as 别名]
# 或者: from threading.Thread import alive [as 别名]
def main():
# Spawn a new thread that runs sleepy
t = Thread(target=sleepy, args=(0,))
try:
# Start the thread
t.start()
# If the child thread is still running
while t.is_alive():
# Try to join the child thread back to parent for 0.5 seconds
t.join(0.5)
# When ctrl+c is received
except KeyboardInterrupt as e:
# Set the alive attribute to false
t.alive = False
# Block until child thread is joined back to the parent
t.join()
# Exit with error code
sys.exit(e)