当前位置: 首页>>代码示例>>Python>>正文


Python Worker.is_running方法代码示例

本文整理汇总了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()
开发者ID:eight04,项目名称:pyWorker,代码行数:36,代码来源:test.py

示例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())
开发者ID:eight04,项目名称:pyWorker,代码行数:15,代码来源:test.py


注:本文中的worker.Worker.is_running方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。