本文整理汇总了Python中worker.Worker.is_running方法的典型用法代码示例。如果您正苦于以下问题:Python Worker.is_running方法的具体用法?Python Worker.is_running怎么用?Python Worker.is_running使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类worker.Worker
的用法示例。
在下文中一共展示了Worker.is_running方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_daemon
# 需要导入模块: from worker import Worker [as 别名]
# 或者: from worker.Worker import is_running [as 别名]
def test_daemon(self):
from worker import current, Worker
with self.subTest("main thread is not deamon"):
self.assertFalse(current().is_daemon())
with self.subTest("thread is not daemon by default"):
thread = Worker().start()
self.assertFalse(thread.is_daemon())
thread.stop().join()
with self.subTest("should inherit parent if not set"):
a = Worker(daemon=True).start()
self.assertTrue(a.is_daemon())
b = Worker(parent=a).start()
self.assertTrue(b.is_daemon())
a.stop().join()
with self.subTest("parent will wait non-daemon child thread"):
a = Worker().start()
b = Worker(parent=a).start()
a.stop().join()
self.assertFalse(b.is_running())
with self.subTest("parent won't wait daemon child thread"):
def blocker():
time.sleep(1)
a = Worker().start()
b = Worker(blocker, parent=a, daemon=True).start()
a.stop().join()
self.assertTrue(b.is_running())
b.join()
示例2: test_child_thread
# 需要导入模块: from worker import Worker [as 别名]
# 或者: from worker.Worker import is_running [as 别名]
def test_child_thread(self):
from worker import Worker
parent = Worker()
child = Worker(parent=parent)
parent.start()
child.start()
parent.stop().join()
self.assertFalse(parent.is_running())
self.assertFalse(child.is_running())