Beispiel #1
0
    def test_background_task_thread_critical(self):
        def t(a, x):
            result.background_task_thread = a + x

        background_task(t, priority=TASK_CRITICAL)(3, x=4)
        wait()
        self.assertEqual(result.background_task_thread, 7)
Beispiel #2
0
    def test_background_task_thread(self):
        def t(a, x):
            result.background_task_thread = a + x

        background_task(t)(2, x=3)
        wait()
        self.assertEqual(result.background_task_thread, 5)
Beispiel #3
0
    def test_background_task_mp(self):
        def callback(res):
            result.background_task_mp = res

        from mp import test_mp
        background_task(test_mp, tt=TT_MP, callback=callback)(3, x=7)
        wait()
        self.assertEqual(result.background_task_mp, 10)
Beispiel #4
0
    def test_result_thread(self):
        def t1():
            return 777

        def t2():
            return 111

        task1 = background_task(t1)()
        task2 = background_task(t2)()
        self.assertEqual(wait_completed((task1, task2)), [777, 111])
Beispiel #5
0
    def test_result_async(self):
        def t1():
            return 555

        aloop = task_supervisor.create_aloop('test3')
        t = background_task(t1, loop='test3')()
        wait_completed([t])
        self.assertEqual(t.result, 555)
Beispiel #6
0
    def test_aloop_run(self):
        async def t1():
            result.test_aloop_background_task = 1

        async def t2(x):
            return x * 2

        a = task_supervisor.create_aloop('test2')
        t = background_task(t1, loop='test2')()
        wait_completed([t])
        self.assertEqual(result.test_aloop_background_task, 1)
        self.assertEqual(a.run(t2(2)), 4)
Beispiel #7
0
    def test_result_mp(self):

        from mp import test2

        t = background_task(test2, tt=TT_MP)()
        self.assertEqual(wait_completed(t), 999)