Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
def coro():
with pytest.raises(TypeError):
result = AWAIT(simple_coro(2, '3'))
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)
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())
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)
def __exit__(self, *args):
return thread.AWAIT(self.__aexit__(*args))
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)
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)
def __exit__(self, *args):
return thread.AWAIT(self.__exit__(*args))
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)