How to use the curio.thread.AWAIT function in curio

To help you get started, we’ve selected a few curio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dabeaz / curio / tests / test_thread.py View on Github external
def func():
        with disable_cancellation():
            AWAIT(sleep(1))
            assert True

            with enable_cancellation():
                AWAIT(sleep(2))

            assert isinstance(AWAIT(check_cancellation()), TaskTimeout)

        with pytest.raises(TaskTimeout):
            AWAIT(sleep(2))
github dabeaz / curio / tests / test_thread.py View on Github external
def coro():
        with pytest.raises(TypeError):
            result = AWAIT(simple_coro(2, '3'))
github dabeaz / curio / tests / test_thread.py View on Github external
def task():
        task1 = AWAIT(spawn(add, 1, 1))
        task2 = AWAIT(spawn(add, 2, 2))
        task3 = AWAIT(spawn(add, 3, 3))
        w = TaskGroup([task1, task2, task3])
        with w:
            for task in w:
                result = AWAIT(task.join())
                results.append(result)
github dabeaz / curio / tests / test_thread.py View on Github external
def func2():
        results.append('func2')
        # Awaiting on an async-thread function should work, but it should stay in the same thread
        AWAIT(func1, threading.currentThread())
github dabeaz / curio / curio / io.py View on Github external
def send(self, data, flags=0):
        while True:
            try:
                return self._socket_send(data, flags)
            except WantWrite:
                thread.AWAIT(_write_wait, self._fileno)
            except WantRead: 
                thread.AWAIT(_read_wait, self._fileno)
github dabeaz / curio / curio / sync.py View on Github external
def __exit__(self, *args):
        return thread.AWAIT(self.__aexit__(*args))
github dabeaz / curio / curio / io.py View on Github external
def recvfrom(self, buffersize, flags=0):
        while True:
            try:
                return self._socket.recvfrom(buffersize, flags)
            except WantRead:
                thread.AWAIT(_read_wait, self._fileno)
            except WantWrite:
                thread.AWAIT(_write_wait, self._fileno)
github dabeaz / curio / curio / io.py View on Github external
def do_handshake(self):
        while True:
            try:
                return self._socket.do_handshake()
            except WantRead:
                thread.AWAIT(_read_wait, self._fileno)
            except WantWrite:
                thread.AWAIT(_write_wait, self._fileno)
github dabeaz / curio / curio / io.py View on Github external
def __exit__(self, *args):
        return thread.AWAIT(self.__exit__(*args))
github dabeaz / curio / curio / io.py View on Github external
def recvmsg(self, bufsize, ancbufsize=0, flags=0):
        while True:
            try:
                return self._socket.recvmsg(bufsize, ancbufsize, flags)
            except WantRead:
                thread.AWAIT(_read_wait, self._fileno)