Beispiel #1
0
 def test_timeout_other(self):
     t = tasks.spawn(timers.sleep(100))
     timers.timeout_after(0, task=t)
     kernels.run(timeout=1)
     self.assertTrue(t.is_completed())
     with self.assertRaises(timers.Timeout):
         t.get_result_nonblocking()
Beispiel #2
0
async def do_timeout_after(duration):
    timers.timeout_after(duration)
    try:
        await timers.sleep(duration * 2)
    except timers.Timeout:
        pass
    else:
        raise RuntimeError('Timeout was not raised')
Beispiel #3
0
async def timeout_after(duration):
    logging.info('timeout_after: %f', duration)
    timers.timeout_after(duration)
    try:
        await locks.Event().wait()
    except errors.TaskCancellation:
        logging.info('timeout_after is cancelled')
        raise
Beispiel #4
0
    def test_context(self):

        with self.assertRaisesRegex(LookupError, r'ContextVar.*kernel'):
            timers.timeout_after(0)

        @kernels.with_kernel
        def test_with_kernel():
            with self.assertRaisesRegex(LookupError, r'no current task'):
                timers.timeout_after(0)

        test_with_kernel()
Beispiel #5
0
async def handle_signals(duration):
    print('pid: %d' % os.getpid())
    timers.timeout_after(duration)
    with signals.SignalSource() as source:
        signums = [signal.SIGINT, signal.SIGTERM]
        print('handle signals for %.3f seconds: %r' % (duration, signums))
        for signum in signums:
            source.enable(signum)
        try:
            while True:
                print('receive signal: %r' % await source.get())
        except timers.Timeout:
            print('timeout')
Beispiel #6
0
 def start_exiting():
     if agent_queue.is_closed():
         return False
     agent_queue.close()
     graceful_exit.set()
     stack.enter_context(
         timers.timeout_after(grace_period, task=main_task)
     )
     return True
Beispiel #7
0
 async def sendfile(self, file):
     ASSERT.true(self._has_begun)
     # sendfile can be called only once.
     ASSERT.is_(self._send_mechanism, _SendMechanisms.UNDECIDED)
     ASSERT.not_none(file)
     self._send_mechanism = _SendMechanisms.SENDFILE
     await self._headers_sent.wait()
     with timers.timeout_after(self._SENDFILE_TIMEOUT):
         return await self._sock.sendfile(file)
Beispiel #8
0
 async def _get_request(self):
     try:
         with timers.timeout_after(self._KEEP_ALIVE_IDLE_TIMEOUT):
             environ = await self._request_queue.get()
     except _RequestError as exc:
         LOG.warning('invalid request: %s %s', exc.status, exc)
         await self._put_short_response(exc.status, False)
         raise _SessionExit from None
     except timers.Timeout:
         LOG.debug('keep-alive idle timeout')
         raise _SessionExit from None
     if environ is None:
         raise _SessionExit
     return environ
Beispiel #9
0
 async def _send_all(self, data):
     data = memoryview(data)
     num_sent = 0
     while num_sent < len(data):
         with timers.timeout_after(self._SEND_TIMEOUT):
             num_sent += await self._sock.send(data[num_sent:])
Beispiel #10
0
 def test_with_kernel():
     with self.assertRaisesRegex(LookupError, r'no current task'):
         timers.timeout_after(0)