Fixed issue with silent timeouts in scopes
This commit is contained in:
parent
09ad7e12e3
commit
351a212ccd
|
@ -1,4 +1,4 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (StructuredIO)" project-jdk-type="Python SDK" />
|
||||
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10 (structio)" project-jdk-type="Python SDK" />
|
||||
</project>
|
|
@ -70,10 +70,6 @@ class TaskScope:
|
|||
|
||||
def __exit__(self, exc_type: type, exc_val: BaseException, exc_tb):
|
||||
current_loop().close_scope(self)
|
||||
if exc_val and isinstance(exc_val, structio.TimedOut):
|
||||
self.cancelled = True
|
||||
return self.silent
|
||||
return False
|
||||
|
||||
# Just a recursive helper
|
||||
def _get_children(self, lst=None):
|
||||
|
|
|
@ -249,9 +249,13 @@ class FIFOKernel(BaseKernel):
|
|||
def check_scopes(self):
|
||||
for scope in self.pool.scope.children:
|
||||
if scope.get_actual_timeout() <= self.clock.current_time():
|
||||
error = TimedOut("timed out")
|
||||
error.scope = scope
|
||||
self.throw(scope.owner, error)
|
||||
if scope.silent:
|
||||
self.cancel_scope(scope)
|
||||
self.reschedule(scope.owner)
|
||||
else:
|
||||
error = TimedOut("timed out")
|
||||
error.scope = scope
|
||||
self.throw(scope.owner, error)
|
||||
|
||||
def wakeup(self):
|
||||
while (
|
||||
|
|
|
@ -160,7 +160,7 @@ async def connect_socket(
|
|||
# RFC 8305 specifies that if we get addresses of different families,
|
||||
# our first two connection attempts should be using different ones
|
||||
# (in english: if getaddrinfo() returns, say, 2 IPV4 addresses and one IPV6
|
||||
# addr, then we have to make sure our first and second attempt use one
|
||||
# address, then we have to make sure our first and second attempt use one
|
||||
# of each type)
|
||||
for i in range(1, len(hosts)):
|
||||
# If the family of the ith socket (skipping
|
||||
|
@ -188,10 +188,10 @@ async def connect_socket(
|
|||
sockets.append(attempt_sock)
|
||||
if source_address:
|
||||
# This trick (again stolen from Trio), lets us
|
||||
# bind to a given addr without actually busying
|
||||
# bind to a given address without actually busying
|
||||
# up a local port up until the moment where we actually
|
||||
# need to connect. That way, we can perform as many connection
|
||||
# attempts as we want from a given source addr without ever
|
||||
# attempts as we want from a given source address without ever
|
||||
# worrying about running out of local ports
|
||||
try:
|
||||
attempt_sock.setsockopt(
|
||||
|
@ -208,7 +208,7 @@ async def connect_socket(
|
|||
except OSError:
|
||||
# Almost hit the 120 character line, phew...
|
||||
raise OSError(
|
||||
f"Source addr {source_address!r} is incompatible with remote addr {addr!r}"
|
||||
f"Source address {source_address!r} is incompatible with remote address {addr!r}"
|
||||
)
|
||||
await attempt_sock.connect(addr)
|
||||
# Hooray! Connection was successful. Record the socket
|
||||
|
@ -218,7 +218,7 @@ async def connect_socket(
|
|||
sockets.remove(attempt_sock)
|
||||
scope.cancel()
|
||||
except OSError:
|
||||
# Welp, this attempt failed. Right now, we just ignore the error (we'll
|
||||
# Well, this attempt failed. Right now, we just ignore the error (we'll
|
||||
# fail with OSError later if all connection attempts fail), but we should
|
||||
# really have support for ExceptionGroups (coming soon btw), so we can
|
||||
# keep track of all the errors and use fancy stuff like the new except*
|
||||
|
|
Loading…
Reference in New Issue