Пример #1
0
 def test_later(self):
     from worker import current, later, sleep
     
     a = 0
     b = None
     
     def add(value):
         nonlocal a
         nonlocal b
         b = current()
         a += value
         
     current().later(add, 10, timeout=2)
     
     with self.subTest("not yet"):
         sleep(1)
         self.assertEqual(a, 0)
         self.assertEqual(b, None)
     
     with self.subTest("finished"):
         sleep(2)
         self.assertEqual(a, 10)
         self.assertEqual(b, current())
         
     later(add, 10, timeout=2)
     
     with self.subTest("not yet"):
         sleep(1)
         self.assertEqual(a, 10)
         
     with self.subTest("finished"):
         sleep(2)
         self.assertEqual(a, 20)
         self.assertEqual(b, current())
Пример #2
0
 def test_await(self):
     from worker import await_, later
     from time import sleep
     
     a = False
     
     def blocking_task():
         sleep(1)
         
     def task():
         nonlocal a
         a = True
         
     later(task)
     # ensure await_ enter the event loop
     await_(blocking_task)
     self.assertTrue(a)
Пример #3
0
 def test_later_cancel(self):
     from worker import later, sleep
     
     a = False
     def task():
         nonlocal a
         a = True
     pending = later(task, timeout=1)
     sleep(0.5)
     pending.stop()
     sleep(1)
     self.assertFalse(a)
Пример #4
0
        def _(event):
            """After analyze, continue next (library)"""
            try:
                _err, mission = event.data
            except TypeError:
                mission = event.data

            if event.target is self.library_thread:
                uninit_episode(mission)
                if mission.state == "UPDATE":
                    mission_manager.lift("library", mission)

                if mission.state == "ERROR":
                    if self.library_err_count > 10:
                        print("Too many error!")
                        download_ch.pub("LIBRARY_CHECK_UPDATE_FAILED")
                    else:
                        self.library_err_count += 1
                        mission_manager.drop("library", mission)
                        later(self.do_check_update, 5, target=thread)
                    return

                self.do_check_update()