Skip to content

Commit acab26d

Browse files
committed
ansible: improve process.py docs
1 parent edeaa3c commit acab26d

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

ansible_mitogen/process.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,25 @@ def get_cpu_count(default=None):
277277

278278

279279
class Binding(object):
280+
"""
281+
Represent a bound connection for a particular inventory hostname. When
282+
operating in sharded mode, the actual MuxProcess implementing a connection
283+
varies according to the target machine. Depending on the particular
284+
implementation, this class represents a binding to the correct MuxProcess.
285+
"""
280286
def get_child_service_context(self):
281287
"""
282288
Return the :class:`mitogen.core.Context` to which children should
283-
direct ContextService requests, or :data:`None` for the local process.
289+
direct requests for services such as FileService, or :data:`None` for
290+
the local process.
291+
292+
This can be different from :meth:`get_service_context` where MuxProcess
293+
and WorkerProcess are combined, and it is discovered a task is
294+
delegated after being assigned to its initial worker for the original
295+
un-delegated hostname. In that case, connection management and
296+
expensive services like file transfer must be implemented by the
297+
MuxProcess connected to the target, rather than routed to the
298+
MuxProcess responsible for executing the task.
284299
"""
285300
raise NotImplementedError()
286301

@@ -366,8 +381,8 @@ def __init__(self, _init_logging=True):
366381

367382
def _listener_for_name(self, name):
368383
"""
369-
Given a connection stack, return the UNIX listener that should be used
370-
to communicate with it. This is a simple hash of the inventory name.
384+
Given an inventory hostname, return the UNIX listener that should
385+
communicate with it. This is a simple hash of the inventory name.
371386
"""
372387
if len(self._muxes) == 1:
373388
return self._muxes[0].path
@@ -401,10 +416,9 @@ def on_process_exit(self, sock):
401416
This is an :mod:`atexit` handler installed in the top-level process.
402417
403418
Shut the write end of `sock`, causing the receive side of the socket in
404-
every worker process to wake up with a 0-byte reads, and causing their
405-
main threads to wake up and initiate shutdown. After shutting the
406-
socket down, wait for a 0-byte read from the read end, which will occur
407-
after the last child closes the descriptor on exit.
419+
every worker process to return 0-byte reads, and causing their main
420+
threads to wake and initiate shutdown. After shutting the socket down,
421+
wait on each child to finish exiting.
408422
409423
This is done using :mod:`atexit` since Ansible lacks any better hook to
410424
run code during exit, and unless some synchronization exists with
@@ -429,12 +443,13 @@ def on_process_exit(self, sock):
429443

430444
def _initialize(self):
431445
"""
432-
Arrange for classic process model connection multiplexer child
433-
processes to be started, if they are not already running.
446+
Arrange for classic model multiplexers to be started, if they are not
447+
already running.
434448
435-
The parent process picks a UNIX socket path the child will use prior to
436-
fork, creates a socketpair used essentially as a semaphore, then blocks
437-
waiting for the child to indicate the UNIX socket is ready for use.
449+
The parent process picks a UNIX socket path each child will use prior
450+
to fork, creates a socketpair used essentially as a semaphore, then
451+
blocks waiting for the child to indicate the UNIX socket is ready for
452+
use.
438453
439454
:param bool _init_logging:
440455
For testing, if :data:`False`, don't initialize logging.
@@ -533,8 +548,8 @@ class MuxProcess(object):
533548
Implement a subprocess forked from the Ansible top-level, as a safe place
534549
to contain the Mitogen IO multiplexer thread, keeping its use of the
535550
logging package (and the logging package's heavy use of locks) far away
536-
from the clutches of os.fork(), which is used continuously by the
537-
multiprocessing package in the top-level process.
551+
from os.fork(), which is used continuously by the multiprocessing package
552+
in the top-level process.
538553
539554
The problem with running the multiplexer in that process is that should the
540555
multiplexer thread be in the process of emitting a log entry (and holding

0 commit comments

Comments
 (0)