MCPcopy Index your code
hub / github.com/python/cpython / serve_forever

Method serve_forever

Lib/socketserver.py:215–242  ·  view source on GitHub ↗

Handle one request at a time until shutdown. Polls for shutdown every poll_interval seconds. Ignores self.timeout. If you need to do periodic tasks, do them in another thread.

(self, poll_interval=0.5)

Source from the content-addressed store, hash-verified

213 pass
214
215 def serve_forever(self, poll_interval=0.5):
216 """Handle one request at a time until shutdown.
217
218 Polls for shutdown every poll_interval seconds. Ignores
219 self.timeout. If you need to do periodic tasks, do them in
220 another thread.
221 """
222 self.__is_shut_down.clear()
223 try:
224 # XXX: Consider using another file descriptor or connecting to the
225 # socket to wake this up instead of polling. Polling reduces our
226 # responsiveness to a shutdown request and wastes cpu at all other
227 # times.
228 with _ServerSelector() as selector:
229 selector.register(self, selectors.EVENT_READ)
230
231 while not self.__shutdown_request:
232 ready = selector.select(poll_interval)
233 # bpo-35017: shutdown() called during select(), exit immediately.
234 if self.__shutdown_request:
235 break
236 if ready:
237 self._handle_request_noblock()
238
239 self.service_actions()
240 finally:
241 self.__shutdown_request = False
242 self.__is_shut_down.set()
243
244 def shutdown(self):
245 """Stops the serve_forever loop.

Callers

nothing calls this directly

Calls 6

service_actionsMethod · 0.95
clearMethod · 0.45
registerMethod · 0.45
selectMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected