15
15
pass
16
16
17
17
from errno import EAGAIN , ECONNRESET , ETIMEDOUT
18
- from time import monotonic
18
+ from time import monotonic , sleep
19
19
from traceback import print_exception
20
20
21
21
from .authentication import Basic , Token , Bearer , require_authentication
@@ -171,14 +171,17 @@ def _verify_can_start(self, host: str, port: int) -> None:
171
171
except OSError as error :
172
172
raise RuntimeError (f"Cannot start server on { host } :{ port } " ) from error
173
173
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 :
175
177
"""
176
178
Wait for HTTP requests at the given host and port. Does not return.
177
179
Ignores any exceptions raised by the handler function and continues to serve.
178
180
Returns only when the server is stopped by calling ``.stop()``.
179
181
180
182
:param str host: host name or IP address
181
183
:param int port: port
184
+ :param float poll_interval: interval between polls in seconds
182
185
"""
183
186
self .start (host , port )
184
187
@@ -191,6 +194,9 @@ def serve_forever(self, host: str, port: int = 80) -> None:
191
194
except Exception : # pylint: disable=broad-except
192
195
pass # Ignore exceptions in handler function
193
196
197
+ if poll_interval is not None :
198
+ sleep (poll_interval )
199
+
194
200
def start (self , host : str , port : int = 80 ) -> None :
195
201
"""
196
202
Start the HTTP server at the given host and port. Requires calling
0 commit comments