MCPcopy Index your code
hub / github.com/RustPython/RustPython / serve_forever

Method serve_forever

Lib/socketserver.py:218–245  ·  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

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