Exemple #1
0
    def test__add_callback_cancelled_handle(self):
        h = asyncio.Handle(lambda: False, (), self.loop)
        h.cancel()

        self.loop._add_callback(h)
        self.assertFalse(self.loop._scheduled)
        self.assertFalse(self.loop._ready)
Exemple #2
0
    def test_run_once_in_executor_handle(self):
        def cb():
            pass

        self.assertRaises(AssertionError, self.loop.run_in_executor, None,
                          asyncio.Handle(cb, (), self.loop), ('', ))
        self.assertRaises(AssertionError, self.loop.run_in_executor, None,
                          asyncio.TimerHandle(10, cb, (), self.loop))
Exemple #3
0
    def test_run_once_in_executor_cancelled(self):
        def cb():
            pass

        h = asyncio.Handle(cb, (), self.loop)
        h.cancel()

        f = self.loop.run_in_executor(None, h)
        self.assertIsInstance(f, asyncio.Future)
        self.assertTrue(f.done())
        self.assertIsNone(f.result())
Exemple #4
0
    def test_run_once_in_executor_plain(self):
        def cb():
            pass

        h = asyncio.Handle(cb, (), self.loop)
        f = asyncio.Future(loop=self.loop)
        executor = mock.Mock()
        executor.submit.return_value = f

        self.loop.set_default_executor(executor)

        res = self.loop.run_in_executor(None, h)
        self.assertIs(f, res)

        executor = mock.Mock()
        executor.submit.return_value = f
        res = self.loop.run_in_executor(executor, h)
        self.assertIs(f, res)
        self.assertTrue(executor.submit.called)

        f.cancel()  # Don't complain about abandoned Future.
Exemple #5
0
 def call_later(self, delay, callback, *args):
     result = asyncio.Handle(callback, args, self)
     QtCore.QTimer.singleShot(
         int(delay * 1000.0), lambda: result._run()
         if not result._cancelled else None)
     return result