Skip to content

Commit dc7bec0

Browse files
committed
Added pool_interval parameter to Server.serve_forever
1 parent 8c16b27 commit dc7bec0

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

adafruit_httpserver/server.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
pass
1616

1717
from errno import EAGAIN, ECONNRESET, ETIMEDOUT
18-
from time import monotonic
18+
from time import monotonic, sleep
1919
from traceback import print_exception
2020

2121
from .authentication import Basic, Token, Bearer, require_authentication
@@ -171,14 +171,17 @@ def _verify_can_start(self, host: str, port: int) -> None:
171171
except OSError as error:
172172
raise RuntimeError(f"Cannot start server on {host}:{port}") from error
173173

174-
def serve_forever(self, host: str, port: int = 80) -> None:
174+
def serve_forever(
175+
self, host: str, port: int = 80, *, poll_interval: float = None
176+
) -> None:
175177
"""
176178
Wait for HTTP requests at the given host and port. Does not return.
177179
Ignores any exceptions raised by the handler function and continues to serve.
178180
Returns only when the server is stopped by calling ``.stop()``.
179181
180182
:param str host: host name or IP address
181183
:param int port: port
184+
:param float poll_interval: interval between polls in seconds
182185
"""
183186
self.start(host, port)
184187

@@ -191,6 +194,9 @@ def serve_forever(self, host: str, port: int = 80) -> None:
191194
except Exception: # pylint: disable=broad-except
192195
pass # Ignore exceptions in handler function
193196

197+
if poll_interval is not None:
198+
sleep(poll_interval)
199+
194200
def start(self, host: str, port: int = 80) -> None:
195201
"""
196202
Start the HTTP server at the given host and port. Requires calling

0 commit comments

Comments
 (0)