Skip to content

Commit a5619a6

Browse files
committed
Merge remote-tracking branch 'origin/stream-refactor'
* origin/stream-refactor: [stream-refactor] Py3.x test fixes [stream-refactor] mark py24 as allow-fail [stream-refactor] Debian Docker container image initctl [stream-refactor] replace cutpaste with Stream.accept() in mitogen.unix [stream-refactor] fix flake8 errors [stream-refactor] fix testlib assertion format string [stream-refactor] make mitogen-fuse work on Linux [stream-refactor] repair preamble_size.py again [stream-refactor] don't abort Connection until all buffers are empty Normalize docstring formatting [stream-refactor] fix LogHandler.uncork() race [stream-refactor] BufferedWriter must disconenct Stream, not Protocol [stream-refactor] statically link doas binary using musl [stream-refactor] stop writing to /tmp/foo in fd_check.py. [stream-refactor] yet another 2.4 issue in create_child_test [stream-refactor] fix Py2.4 failure by implementing missing Timer method [stream-refactor] allow up to 30 seconds to connect in unix_test [stream-refactor] mark setns module as requiring Python >2.4 [stream-refactor] another 2.4 fix for create_child_test .travis.yml: Add reverse shell spawn for Travis too core: better Side attribute docstrings [stream-refactor] remove one more getuser() usage [stream-refactor] allow doas_test to succeed on CentOS Pin idna==2.7 when running on Python<2.7. [stream-refactor] Py2.4 compat fix for iter_split_test. [stream-refactor] add descriptive task names to _container_prep [stream-refactor] 3.x socket.send() requires bytes [stream-refactor] fix 2.4 syntax error. [stream-refactor] avoid os.wait3() for Py2.4. Allow specifying -vvv to debops_tests. [stream-refactor] send MITO002 earlier module_finder: pass raw file to compile() [stream-refactor] merge stdout+stderr when reporting EofError [stream-refactor] fix crash in detach() / during async/multiple_items_loop.yml [stream-refactor] fix crash in runner/forking_active.yml [stream-refactor] replace old detach_popen() reference ansible: fixturize creation of MuxProcess unix: ensure mitogen.context_id is reset when client disconnects [stream-refactor] make syntax 2.4 compatible [stream-refactor] make trusty our Travis dist. [stream-refactor] fix su_test failure (issue #363) [stream-refactor] more readable log string format [stream-refactor] dont doubly log last partial line [stream-refactor] import fd_check.py used by create_child_test [stream-refactor] port mitogen.buildah, added to master since work began [stream-refactor] fix unix.Listener construction [stream-refactor] fix crash when no stderr present. [stream-refactor] fix Process constructor invocation Add tests/ansible/.*.pid to gitignore (for ansible_mitogen/process.py) Add extra/ to gitignore import release-notes script. [stream-refactor] repaired rest of create_child_test. [stream-refactor] rename Process attrs, fix up more create_child_test [stream-refactor] import incomplete create_child_test issue #482: tests: check for zombie process after test. issue #363: add test. tests: clean up old-style SSH exception catch issue #271: add mitogen__permdenied user to Docker image. ssh: fix issue #271 regression due to refactor, add test. Refactor Stream, introduce quasi-asynchronous connect, much more core: teach iter_split() to break on callback returning False. issue #507: log fatal errors to syslog. testlib: have LogCapturer.raw() return unicode on 2.x. core/master: docstring, repr, and debug log message cleanups parent: remove unused Timer parameter. tests: jail_test fixes. parent: docstring improvements, cfmakeraw() regression. core: introduce Protocol, DelimitedProtocol and BufferedWriter. core: introduce mitogen.core.pipe() tests/bench: import ssh-roundtrip.py. tests: note location of related tests. tests: add real test for doas. tests: install OpenBSD doas port in Debian image. tests: add setns_test that works if password localhost sudo works. Import minimal jail_test. core: move message encoding to Message.pack(), add+refactor tests. master: expect forwarded logs to be in UTF-8. tests: add some UTF-8 to ssh_login_banner to encourage breakage. core: bootstrap FD management improvements core: pending timers should keep broker alive. core: more succinct iter_split(). core: replace UTF8_CODEC with encodings.utf_8.encode() function. docs: remove bytearray from supported types list. core: docstring style cleanups, dead code. testlib: disable lsof warnings due to Docker crap parent: discard cancelled events in TimerList.get_timeout(). core: split out iter_split() for use in parent.py. parent: various style cleanups, remove unused function. issue #170: add TimerList docstrings. core: eliminate some quadratric behaviour from IoLogger issue #170: update Changelog; closes #170. issue #170: add timers to internals.rst. issue #170: implement timers.
2 parents 4fedf88 + 6da991f commit a5619a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+3849
-1977
lines changed

.ci/debops_common_tests.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from __future__ import print_function
44
import os
55
import shutil
6+
import sys
67

78
import ci_lib
89

@@ -68,8 +69,8 @@
6869

6970

7071
with ci_lib.Fold('first_run'):
71-
ci_lib.run('debops common')
72+
ci_lib.run('debops common %s', ' '.join(sys.argv[1:]))
7273

7374

7475
with ci_lib.Fold('second_run'):
75-
ci_lib.run('debops common')
76+
ci_lib.run('debops common %s', ' '.join(sys.argv[1:]))

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ venvs/**
99
MANIFEST
1010
build/
1111
dist/
12+
extra/
13+
tests/ansible/.*.pid
1214
docs/_build/
1315
htmlcov/
1416
*.egg-info

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
sudo: required
2+
dist: trusty
23

34
notifications:
45
email: false
@@ -20,13 +21,19 @@ install:
2021
- .ci/${MODE}_install.py
2122

2223
script:
24+
- .ci/spawn_reverse_shell.py
2325
- .ci/${MODE}_tests.py
2426

2527

2628
# To avoid matrix explosion, just test against oldest->newest and
2729
# newest->oldest in various configuartions.
2830

2931
matrix:
32+
allow_failures:
33+
# Python 2.4 tests are still unreliable
34+
- language: c
35+
env: MODE=mitogen_py24 DISTRO=centos5
36+
3037
include:
3138
# Mitogen tests.
3239
# 2.4 -> 2.4

ansible_mitogen/affinity.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ class FixedPolicy(Policy):
177177
cores, before reusing the second hyperthread of an existing core.
178178
179179
A hook is installed that causes :meth:`reset` to run in the child of any
180-
process created with :func:`mitogen.parent.detach_popen`, ensuring
181-
CPU-intensive children like SSH are not forced to share the same core as
182-
the (otherwise potentially very busy) parent.
180+
process created with :func:`mitogen.parent.popen`, ensuring CPU-intensive
181+
children like SSH are not forced to share the same core as the (otherwise
182+
potentially very busy) parent.
183183
"""
184184
def __init__(self, cpu_count=None):
185185
#: For tests.

ansible_mitogen/module_finder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def get_code(module):
5757
"""
5858
Compile and return a Module's code object.
5959
"""
60-
fp = open(module.path)
60+
fp = open(module.path, 'rb')
6161
try:
6262
return compile(fp.read(), str(module.name), 'exec')
6363
finally:

ansible_mitogen/process.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,15 @@ def clean_shutdown(sock):
7979
MuxProcess, debug logs may appear on the user's terminal *after* the prompt
8080
has been printed.
8181
"""
82-
sock.shutdown(socket.SHUT_WR)
82+
try:
83+
sock.shutdown(socket.SHUT_WR)
84+
except socket.error:
85+
# Already closed. This is possible when tests are running.
86+
LOG.debug('clean_shutdown: ignoring duplicate call')
87+
return
88+
8389
sock.recv(1)
90+
sock.close()
8491

8592

8693
def getenv_int(key, default=0):
@@ -154,8 +161,15 @@ class of problems this worker is intended to avoid.
154161
#: forked WorkerProcesses to contact the MuxProcess
155162
unix_listener_path = None
156163

157-
#: Singleton.
158-
_instance = None
164+
@classmethod
165+
def _reset(cls):
166+
"""
167+
Used to clean up in unit tests.
168+
"""
169+
assert cls.worker_sock is not None
170+
cls.worker_sock.close()
171+
cls.worker_sock = None
172+
os.waitpid(cls.worker_pid, 0)
159173

160174
@classmethod
161175
def start(cls, _init_logging=True):
@@ -178,7 +192,7 @@ def start(cls, _init_logging=True):
178192
mitogen.utils.setup_gil()
179193
cls.unix_listener_path = mitogen.unix.make_socket_path()
180194
cls.worker_sock, cls.child_sock = socket.socketpair()
181-
atexit.register(lambda: clean_shutdown(cls.worker_sock))
195+
atexit.register(clean_shutdown, cls.worker_sock)
182196
mitogen.core.set_cloexec(cls.worker_sock.fileno())
183197
mitogen.core.set_cloexec(cls.child_sock.fileno())
184198

@@ -189,8 +203,8 @@ def start(cls, _init_logging=True):
189203
ansible_mitogen.logging.setup()
190204

191205
cls.original_env = dict(os.environ)
192-
cls.child_pid = os.fork()
193-
if cls.child_pid:
206+
cls.worker_pid = os.fork()
207+
if cls.worker_pid:
194208
save_pid('controller')
195209
ansible_mitogen.logging.set_process_name('top')
196210
ansible_mitogen.affinity.policy.assign_controller()
@@ -308,7 +322,7 @@ def _setup_master(self):
308322
self._setup_responder(self.router.responder)
309323
mitogen.core.listen(self.broker, 'shutdown', self.on_broker_shutdown)
310324
mitogen.core.listen(self.broker, 'exit', self.on_broker_exit)
311-
self.listener = mitogen.unix.Listener(
325+
self.listener = mitogen.unix.Listener.build_stream(
312326
router=self.router,
313327
path=self.unix_listener_path,
314328
backlog=C.DEFAULT_FORKS,

docs/api.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ Connection Methods
383383
the root PID of a running Docker, LXC, LXD, or systemd-nspawn
384384
container.
385385

386+
The setns method depends on the built-in :mod:`ctypes` module, and thus
387+
does not support Python 2.4.
388+
386389
A program is required only to find the root PID, after which management
387390
of the child Python interpreter is handled directly.
388391

docs/changelog.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ Fixes
102102
potential influx of 2.8-related bug reports.
103103

104104

105+
Core Library
106+
~~~~~~~~~~~~
107+
108+
* `#170 <https://github.com/dw/mitogen/issues/170>`_: to better support child
109+
process management and a future asynchronous connect implementation, a
110+
:class:`mitogen.parent.TimerList` API is available.
111+
112+
105113
Thanks!
106114
~~~~~~~
107115

docs/getting_started.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,13 @@ The following built-in types may be used as parameters or return values in
341341
remote procedure calls:
342342

343343
* :class:`bool`
344-
* :class:`bytearray`
345-
* :func:`bytes`
344+
* :func:`bytes` (:class:`str` on Python 2.x)
346345
* :class:`dict`
347346
* :class:`int`
348347
* :func:`list`
349348
* :class:`long`
350-
* :class:`str`
351349
* :func:`tuple`
352-
* :func:`unicode`
350+
* :func:`unicode` (:class:`str` on Python 3.x)
353351

354352
User-defined types may not be used, except for:
355353

docs/internals.rst

Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -15,46 +15,49 @@ Constants
1515
.. autodata:: CHUNK_SIZE
1616

1717

18-
Poller Classes
19-
==============
18+
Pollers
19+
=======
2020

2121
.. currentmodule:: mitogen.core
2222
.. autoclass:: Poller
23-
:members:
23+
:members:
24+
25+
.. currentmodule:: mitogen.parent
26+
.. autoclass:: KqueuePoller
2427

2528
.. currentmodule:: mitogen.parent
2629
.. autoclass:: EpollPoller
2730

2831
.. currentmodule:: mitogen.parent
29-
.. autoclass:: KqueuePoller
32+
.. autoclass:: PollPoller
3033

3134

32-
Latch Class
33-
===========
35+
Latch
36+
=====
3437

3538
.. currentmodule:: mitogen.core
3639
.. autoclass:: Latch
3740
:members:
3841

3942

40-
PidfulStreamHandler Class
41-
=========================
43+
PidfulStreamHandler
44+
===================
4245

4346
.. currentmodule:: mitogen.core
4447
.. autoclass:: PidfulStreamHandler
4548
:members:
4649

4750

48-
Side Class
49-
==========
51+
Side
52+
====
5053

5154
.. currentmodule:: mitogen.core
5255
.. autoclass:: Side
5356
:members:
5457

5558

56-
Stream Classes
57-
==============
59+
Stream
60+
======
5861

5962
.. currentmodule:: mitogen.core
6063
.. autoclass:: BasicStream
@@ -79,83 +82,84 @@ Stream Classes
7982
.. autoclass:: Stream
8083
:members:
8184

82-
83-
Other Stream Subclasses
84-
=======================
85-
8685
.. currentmodule:: mitogen.core
87-
8886
.. autoclass:: IoLogger
8987
:members:
9088

89+
.. currentmodule:: mitogen.core
9190
.. autoclass:: Waker
9291
:members:
9392

9493

95-
Poller Class
96-
============
97-
98-
.. currentmodule:: mitogen.core
99-
.. autoclass:: Poller
100-
:members:
101-
102-
.. currentmodule:: mitogen.parent
103-
.. autoclass:: KqueuePoller
104-
105-
.. currentmodule:: mitogen.parent
106-
.. autoclass:: EpollPoller
107-
108-
109-
Importer Class
110-
==============
94+
Importer
95+
========
11196

11297
.. currentmodule:: mitogen.core
11398
.. autoclass:: Importer
11499
:members:
115100

116101

117-
Responder Class
102+
ModuleResponder
118103
===============
119104

120105
.. currentmodule:: mitogen.master
121106
.. autoclass:: ModuleResponder
122107
:members:
123108

124109

125-
RouteMonitor Class
126-
==================
110+
RouteMonitor
111+
============
127112

128113
.. currentmodule:: mitogen.parent
129114
.. autoclass:: RouteMonitor
130115
:members:
131116

132117

133-
Forwarder Class
134-
===============
118+
TimerList
119+
=========
120+
121+
.. currentmodule:: mitogen.parent
122+
.. autoclass:: TimerList
123+
:members:
124+
125+
126+
Timer
127+
=====
128+
129+
.. currentmodule:: mitogen.parent
130+
.. autoclass:: Timer
131+
:members:
132+
133+
134+
Forwarder
135+
=========
135136

136137
.. currentmodule:: mitogen.parent
137138
.. autoclass:: ModuleForwarder
138139
:members:
139140

140141

141-
ExternalContext Class
142-
=====================
142+
ExternalContext
143+
===============
143144

144145
.. currentmodule:: mitogen.core
145146
.. autoclass:: ExternalContext
146147
:members:
147148

148149

149-
mitogen.master
150-
==============
150+
Process
151+
=======
151152

152153
.. currentmodule:: mitogen.parent
153-
.. autoclass:: ProcessMonitor
154+
.. autoclass:: Process
154155
:members:
155156

156157

157-
Blocking I/O Functions
158-
======================
158+
Helpers
159+
=======
160+
161+
Blocking I/O
162+
------------
159163

160164
These functions exist to support the blocking phase of setting up a new
161165
context. They will eventually be replaced with asynchronous equivalents.
@@ -167,17 +171,17 @@ context. They will eventually be replaced with asynchronous equivalents.
167171
.. autofunction:: write_all
168172

169173

170-
Subprocess Creation Functions
171-
=============================
174+
Subprocess Functions
175+
------------
172176

173177
.. currentmodule:: mitogen.parent
174178
.. autofunction:: create_child
175179
.. autofunction:: hybrid_tty_create_child
176180
.. autofunction:: tty_create_child
177181

178182

179-
Helper Functions
180-
================
183+
Helpers
184+
-------
181185

182186
.. currentmodule:: mitogen.core
183187
.. autofunction:: to_text

0 commit comments

Comments
 (0)