Skip to content

Commit b710e0b

Browse files
committed
[Update] server: polling loop with timeout to reevaluate condition
1 parent 5ca115a commit b710e0b

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/py/extra/server.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,13 +307,21 @@ async def Serve(
307307
if options.condition and not options.condition():
308308
break
309309
try:
310-
client, _ = await loop.sock_accept(server)
310+
client, _ = (
311+
await asyncio.wait_for(
312+
loop.sock_accept(server), timeout=options.timeout
313+
)
314+
if options.timeout
315+
else loop.sock_accept(server)
316+
)
311317
# NOTE: Should do something with the tasks
312318
task = loop.create_task(
313319
cls.OnRequest(app, client, loop=loop, options=options)
314320
)
315321
tasks.add(task)
316322
task.add_done_callback(tasks.discard)
323+
except asyncio.TimeoutError:
324+
continue
317325
except OSError as e:
318326
# This can be: [OSError] [Errno 24] Too many open files
319327
if e.errno == 24:

0 commit comments

Comments
 (0)