ansible: improve process.py docs

pull/612/head
David Wilson 5 years ago
parent edeaa3c6ee
commit acab26d796

@ -277,10 +277,25 @@ def get_cpu_count(default=None):
class Binding(object): class Binding(object):
"""
Represent a bound connection for a particular inventory hostname. When
operating in sharded mode, the actual MuxProcess implementing a connection
varies according to the target machine. Depending on the particular
implementation, this class represents a binding to the correct MuxProcess.
"""
def get_child_service_context(self): def get_child_service_context(self):
""" """
Return the :class:`mitogen.core.Context` to which children should Return the :class:`mitogen.core.Context` to which children should
direct ContextService requests, or :data:`None` for the local process. direct requests for services such as FileService, or :data:`None` for
the local process.
This can be different from :meth:`get_service_context` where MuxProcess
and WorkerProcess are combined, and it is discovered a task is
delegated after being assigned to its initial worker for the original
un-delegated hostname. In that case, connection management and
expensive services like file transfer must be implemented by the
MuxProcess connected to the target, rather than routed to the
MuxProcess responsible for executing the task.
""" """
raise NotImplementedError() raise NotImplementedError()
@ -366,8 +381,8 @@ class ClassicWorkerModel(WorkerModel):
def _listener_for_name(self, name): def _listener_for_name(self, name):
""" """
Given a connection stack, return the UNIX listener that should be used Given an inventory hostname, return the UNIX listener that should
to communicate with it. This is a simple hash of the inventory name. communicate with it. This is a simple hash of the inventory name.
""" """
if len(self._muxes) == 1: if len(self._muxes) == 1:
return self._muxes[0].path return self._muxes[0].path
@ -401,10 +416,9 @@ class ClassicWorkerModel(WorkerModel):
This is an :mod:`atexit` handler installed in the top-level process. This is an :mod:`atexit` handler installed in the top-level process.
Shut the write end of `sock`, causing the receive side of the socket in Shut the write end of `sock`, causing the receive side of the socket in
every worker process to wake up with a 0-byte reads, and causing their every worker process to return 0-byte reads, and causing their main
main threads to wake up and initiate shutdown. After shutting the threads to wake and initiate shutdown. After shutting the socket down,
socket down, wait for a 0-byte read from the read end, which will occur wait on each child to finish exiting.
after the last child closes the descriptor on exit.
This is done using :mod:`atexit` since Ansible lacks any better hook to This is done using :mod:`atexit` since Ansible lacks any better hook to
run code during exit, and unless some synchronization exists with run code during exit, and unless some synchronization exists with
@ -429,12 +443,13 @@ class ClassicWorkerModel(WorkerModel):
def _initialize(self): def _initialize(self):
""" """
Arrange for classic process model connection multiplexer child Arrange for classic model multiplexers to be started, if they are not
processes to be started, if they are not already running. already running.
The parent process picks a UNIX socket path the child will use prior to The parent process picks a UNIX socket path each child will use prior
fork, creates a socketpair used essentially as a semaphore, then blocks to fork, creates a socketpair used essentially as a semaphore, then
waiting for the child to indicate the UNIX socket is ready for use. blocks waiting for the child to indicate the UNIX socket is ready for
use.
:param bool _init_logging: :param bool _init_logging:
For testing, if :data:`False`, don't initialize logging. For testing, if :data:`False`, don't initialize logging.
@ -533,8 +548,8 @@ class MuxProcess(object):
Implement a subprocess forked from the Ansible top-level, as a safe place Implement a subprocess forked from the Ansible top-level, as a safe place
to contain the Mitogen IO multiplexer thread, keeping its use of the to contain the Mitogen IO multiplexer thread, keeping its use of the
logging package (and the logging package's heavy use of locks) far away logging package (and the logging package's heavy use of locks) far away
from the clutches of os.fork(), which is used continuously by the from os.fork(), which is used continuously by the multiprocessing package
multiprocessing package in the top-level process. in the top-level process.
The problem with running the multiplexer in that process is that should the The problem with running the multiplexer in that process is that should the
multiplexer thread be in the process of emitting a log entry (and holding multiplexer thread be in the process of emitting a log entry (and holding

Loading…
Cancel
Save