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

Method collect_children

Lib/socketserver.py:566–599  ·  view source on GitHub ↗

Internal routine to wait for children that have exited.

(self, *, blocking=False)

Source from the content-addressed store, hash-verified

564 block_on_close = True
565
566 def collect_children(self, *, blocking=False):
567 """Internal routine to wait for children that have exited."""
568 if self.active_children is None:
569 return
570
571 # If we're above the max number of children, wait and reap them until
572 # we go back below threshold. Note that we use waitpid(-1) below to be
573 # able to collect children in size(<defunct children>) syscalls instead
574 # of size(<children>): the downside is that this might reap children
575 # which we didn't spawn, which is why we only resort to this when we're
576 # above max_children.
577 while len(self.active_children) >= self.max_children:
578 try:
579 pid, _ = os.waitpid(-1, 0)
580 self.active_children.discard(pid)
581 except ChildProcessError:
582 # we don't have any children, we're done
583 self.active_children.clear()
584 except OSError:
585 break
586
587 # Now reap all defunct children.
588 for pid in self.active_children.copy():
589 try:
590 flags = 0 if blocking else os.WNOHANG
591 pid, _ = os.waitpid(pid, flags)
592 # if the child hasn't exited yet, pid will be 0 and ignored by
593 # discard() below
594 self.active_children.discard(pid)
595 except ChildProcessError:
596 # someone else reaped it
597 self.active_children.discard(pid)
598 except OSError:
599 pass
600
601 def handle_timeout(self):
602 """Wait for zombies after self.timeout seconds of inactivity.

Callers 3

handle_timeoutMethod · 0.95
service_actionsMethod · 0.95
server_closeMethod · 0.95

Calls 4

lenFunction · 0.85
discardMethod · 0.45
clearMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected