1515 pass
1616
1717from errno import EAGAIN , ECONNRESET , ETIMEDOUT
18- from time import monotonic
18+ from time import monotonic , sleep
1919from traceback import print_exception
2020
2121from .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