Skip to content

Commit

Permalink
[Update] server: polling loop with timeout to reevaluate condition
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien committed Sep 9, 2024
1 parent 5ca115a commit b710e0b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/py/extra/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,13 +307,21 @@ async def Serve(
if options.condition and not options.condition():
break
try:
client, _ = await loop.sock_accept(server)
client, _ = (
await asyncio.wait_for(
loop.sock_accept(server), timeout=options.timeout
)
if options.timeout
else loop.sock_accept(server)
)
# NOTE: Should do something with the tasks
task = loop.create_task(
cls.OnRequest(app, client, loop=loop, options=options)
)
tasks.add(task)
task.add_done_callback(tasks.discard)
except asyncio.TimeoutError:
continue
except OSError as e:
# This can be: [OSError] [Errno 24] Too many open files
if e.errno == 24:
Expand Down

0 comments on commit b710e0b

Please sign in to comment.