Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mitogen
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
mitogen
Commits
858b01e7
Commit
858b01e7
authored
Mar 17, 2018
by
David Wilson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
issue #150: add docstrings.
parent
6940b230
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
12 deletions
+26
-12
ansible_mitogen/process.py
ansible_mitogen/process.py
+26
-12
No files found.
ansible_mitogen/process.py
View file @
858b01e7
...
@@ -46,17 +46,20 @@ import ansible_mitogen.services
...
@@ -46,17 +46,20 @@ import ansible_mitogen.services
class
MuxProcess
(
object
):
class
MuxProcess
(
object
):
"""
"""
This implements a process forked from the Ansible top-level process as a
Implement a subprocess forked from the Ansible top-level, as a safe place
safe place to contain the Mitogen IO multiplexer thread, keeping its use of
to contain the Mitogen IO multiplexer thread, keeping its use of the
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
in the top-level
from the clutches of os.fork(), which is used continuously
by the
process.
multiprocessing package 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
its lock) at the point of fork, in the child, the first attempt to log any
its lock) at the point of fork, in the child, the first attempt to log any
log entry using the same handler will deadlock the child, as in the memory
log entry using the same handler will deadlock the child, as in the memory
image the child received, the lock will always be marked held.
image the child received, the lock will always be marked held.
See https://bugs.python.org/issue6721 for a thorough description of the
class of problems this worker is intended to avoid.
"""
"""
#: In the top-level process, this references one end of a socketpair(),
#: In the top-level process, this references one end of a socketpair(),
...
@@ -82,6 +85,13 @@ class MuxProcess(object):
...
@@ -82,6 +85,13 @@ class MuxProcess(object):
@
classmethod
@
classmethod
def
start
(
cls
):
def
start
(
cls
):
"""
Arrange for the subprocess to be started, if it is not already running.
The parent process picks a UNIX socket path the child will use prior to
fork, creates a socketpair used essentially as a semaphore, then blocks
waiting for the child to indicate the UNIX socket is ready for use.
"""
if
cls
.
worker_sock
is
not
None
:
if
cls
.
worker_sock
is
not
None
:
return
return
...
@@ -100,18 +110,22 @@ class MuxProcess(object):
...
@@ -100,18 +110,22 @@ class MuxProcess(object):
cls
.
worker_sock
.
close
()
cls
.
worker_sock
.
close
()
cls
.
worker_sock
=
None
cls
.
worker_sock
=
None
self
=
cls
()
self
=
cls
()
self
.
ru
n
()
self
.
worker_mai
n
()
sys
.
exit
()
sys
.
exit
()
def
run
(
self
):
def
worker_main
(
self
):
"""
The main function of for the mux process: setup the Mitogen broker
thread and ansible_mitogen services, then sleep waiting for the socket
connected to the parent to be closed (indicating the parent has died).
"""
self
.
_setup_master
()
self
.
_setup_master
()
self
.
_setup_services
()
self
.
_setup_services
()
# Let the parent know our listening socket is ready.
self
.
child_sock
.
send
(
'1'
)
self
.
child_sock
.
send
(
'1'
)
try
:
# Block until the socket is closed, which happens on parent exit.
self
.
child_sock
.
recv
(
1
)
self
.
child_sock
.
recv
(
1
)
except
Exception
,
e
:
print
'do e'
,
e
pass
def
_setup_master
(
self
):
def
_setup_master
(
self
):
"""
"""
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment