Commit Graph

1045 Commits (master)

Author SHA1 Message Date
David Wilson ed8acb5153 master: sysconfig did not exist until 2.7. 5 years ago
David Wilson 5eb10aacef master: fix _is_stdlib_path() failure on Ubuntu. 5 years ago
David Wilson 72ab917c89 issue #590: add FinderMethod docstrings. 5 years ago
David Wilson 875ff5c060 issue #590: refactor ModuleFinder and teach it a new special case.
Now it's possible to find both packages and modules when the
sys.modules[...] state for the package/module is junk. Previously only
modules were possible.

This also refactors things to make writing better tests for all these
cases much simpler.
5 years ago
David Wilson 8f940e2ccb issue #590: teach importer to handle self-replacing modules 5 years ago
David Wilson ba2c65d5ef Bump version for release. 5 years ago
David Wilson ee62c57c9d issue #576: fix Kwargs minor version check.
Unicode kwargs were introduced in Python 2.6.5, not 2.6.0.
5 years ago
David Wilson c255a8b562 Bump version for release. 5 years ago
David Wilson bd4d55dc90 issue #550: parent: add explanatory comment. 5 years ago
David Wilson 87c8ab4323 issue #550: fix up TTY ioctls on WSL 2016 Anniversary Update 5 years ago
David Wilson ae8ba24f59 service: make service list optional.
Used by the new work.
5 years ago
David Wilson d51e70636d os_fork: more doc tweaks 5 years ago
David Wilson 7763549653 os_fork: more doc tweaks 5 years ago
David Wilson add357a029 os_fork: yet more doc tidyup 5 years ago
David Wilson 0a66ca72ef os_fork: more doc tweaks 5 years ago
David Wilson 5dc0bd6f8d os_fork: clean up docs 5 years ago
David Wilson c413d53144 os_fork: python 3 fixes and tests. 5 years ago
David Wilson 18b984a0b4 issue #535: activate Corker on 2.4 in master too. 5 years ago
David Wilson 06e52ca89f issue #535: wire mitogen.os_fork into Broker and Pool. 5 years ago
David Wilson c1d73e1f4f issue #535: parent: add create_socketpair(size=..) parameter. 5 years ago
David Wilson 63f4864b21 issue #535: introduce mitogen.os_fork module and Corker class. 5 years ago
David Wilson 514d35fd10 issue #535: service: support Pool.defer() like Broker.defer() 5 years ago
David Wilson eb9ec26622 issue #535: core: unicode.encode() may take importer lock on 2.x
Found on Python 2.4, where import happens immediately following connect.

- Main thread executes import statement, triggers request to parent
- Broker thread attempts to deliver request via Router
- Router discovers parent has disconnected, prepares a dead message
- .dead() calls unicode.encode() to format reason string
- .encode() attemptsto import a codec module
- deadlock

----

(gdb) pystack
/usr/local/python2.4.6/lib/python2.4/encodings/__init__.py (69): search_function
<stdin> (733): dead
<stdin> (2717): _maybe_send_dead
<stdin> (2724): _invoke
<stdin> (2749): _async_route
<stdin> (1635): _receive_one
<stdin> (1603): _internal_receive
<stdin> (1613): on_receive
<stdin> (2931): _call
<stdin> (2942): _loop_once
<stdin> (2988): _do_broker_main
<stdin> (545): _profile_hook
<stdin> (3007): _broker_main
/usr/local/python2.4.6/lib/python2.4/threading.py (420): run
/usr/local/python2.4.6/lib/python2.4/threading.py (424): __bootstrap
5 years ago
David Wilson 72862f0bb9 issue #535: docs: fix up Select doc 5 years ago
David Wilson b3f592acee issue #535: core/select: support selecting from Latches. 5 years ago
David Wilson 7d0480e8bd core: increase cookie field lengths to 64-bit; closes #545. 5 years ago
David Wilson ca63c26e01 core: Make Latch.put(obj=) optional. 5 years ago
David Wilson 9bcd2ec56c issue #542: return of select poller, new selection logic 5 years ago
David Wilson e010667230 Bump version for release. 5 years ago
David Wilson 2a8567b432 core: serialize calls to _service_stub_main().
See comment.
5 years ago
David Wilson d4c0250083 issue #532: PushFileService race.
There has always been a race in PushFileService since given a parent
asked to forward modules to two children via some intermediary:

    interm = router.local()
    c1 = router.local(via=interm)
    c2 = router.local(via=interm)

    service.propagate_to(c1, 'foo/bar.py')
    service.propagate_to(c2, 'foo/bar.py')

Two calls will be emitted to 'interm':

    PushFileService.store_and_forward(c1, 'foo/bar.py', [blob])
    PushFileService.store(c2, 'foo/bar.py')

Which will be processed in-order up to the point where service pool
threads in 'interm' are woken to process the message.

While it is guaranteed store_and_forward() will be processed first, no
guarantee existed that its assigned pool thread would wake and take
_lock first, thus it was possible for forward() to win the race, and for
a request to arrive to forward a file that had not been placed in local
cache yet.

Here we get rid of SerializedInvoker entirely, as it is partially to
blame for hiding the race: SerializedInvoker can only ensure no two
messages are processed simultaneously, it cannot ensure the messages are
processed in their intended order.

Instead, teach forward() that it may be called before
store_and_forward(), and if that is the case, to place the forward
request on to _waiters alongside any local threads blocked in get().
5 years ago
David Wilson 1f77d24bec Update copyright year everywhere. 5 years ago
David Wilson 7ff4e6694c issue #536: rework how 2.3-compatible simplejson is served
Regardless of the version of simplejson loaded in the master, load up
the ModuleResponder cache with our 2.4-compatible version.

To cope with simplejson being loaded due to modules like ec2_group that
try to import it before importing 'json', also update target.py to
remove it from the whitelist if a local 'json' module import succeeds.
5 years ago
David Wilson fa0c25bb2d Bump version for release. 5 years ago
David Wilson 78ec634dab issue #481: core: preserve stderr TTY FD if one is present.
Since 802de6a8d5, sudo on CentOS 5 had
begun failing due to a TTY FD leak in the parent process being fixed.

The old versions of sudo doesn't hang around after starting a child --
they exec the privilege-escalated child process on top of themselves,
meaning no spare copy of the TTY FD is kept alive by sudo.

When the child starts up, it replaces stdio with IoLoggers, including
the inherited stderr FD connected to DiagLogStream/the slave PTY. When
the last process closes a slave PTY, the kernel sends SIGHUP to any
processes still having it as the controlling TTY.

Therefore we must either ignore SIGHUP until the first stage has been
waited on (since the first stage also preserve the FD), or dup the
inherited TTY FD and keep it around forever.

Wasting one FD seems less annoying than modifying process signals for
all potential library users, so that is the approach taken here.
5 years ago
David Wilson b263e01867 issue #481: avoid crash if disconnect occurs during forward_modules() 5 years ago
David Wilson 4abd34e7a6 issue #520: add AIX auth failure string to su. 5 years ago
David Wilson 5ae7464011 core: cProfile is not available in 2.4. 5 years ago
David Wilson 54835d4c9b service: fix PushFileService exception
[costapp]

ERROR! [pid 25135] 21:10:56.284733 E mitogen.ctx.ssh.35.200.203.48: mitogen: While calling no-reply method PushFileService.forward
Traceback (most recent call last):
  File "master:/home/dmw/src/mitogen/mitogen/service.py", line 260, in _invoke
    ret = method(**kwargs)
  File "master:/home/dmw/src/mitogen/mitogen/service.py", line 718, in forward
    self._forward(path, context)
  File "master:/home/dmw/src/mitogen/mitogen/service.py", line 633, in _forward
    stream = self.router.stream_by_id(context.context_id)
AttributeError: 'unicode' object has no attribute 'context_id'
^C [ERROR]: User interrupted execution
5 years ago
David Wilson 23d7a961e7 service: start pool shutdown on broker shutdown. 5 years ago
David Wilson 85cfa3b0f5 master: .encode() needed for Py3. 5 years ago
David Wilson 1d509d03ff issue #508: master: minify_safe_re must be bytes for Py3. 5 years ago
David Wilson 0e193c223c issue #508: master: minify all Mitogen/ansible_mitogen sources.
Minify-safe files are marked with a magical "# !mitogen: minify_safe"
comment anywhere in the file, which activates the minifier. The result
is naturally cached by ModuleResponder, therefore lru_cache is gone too.

Given:

    import os, mitogen
    @mitogen.main()
    def main(router):
        c = router.ssh(hostname='k3')
        c.call(os.getpid)
        router.sudo(via=c)

SSH footprint drops from 56.2 KiB to 42.75 KiB (-23.9%)
Ansible "shell: hostname" drops 149.26 KiB to 117.42 KiB (-21.3%)
5 years ago
David Wilson cfb94e463f parent: PartialZlib docstrings. 5 years ago
David Wilson 9adc38d8ec parent: pre-cache bootstrap if possible.
When the interpreter is modern enough, use zlib.compressobj() to
pre-compress the unchanging parts of the bootstrap once, then use
compressobj.copy() to append just the context's config during stream
construction.

Before: 100 loops, best of 3: 5.81 msec per loop
After: 10000 loops, best of 3: 35.9 usec per loop

With 100 targets this is enough to knock 6 seconds off startup, at 500
targets it becomes half a minute.

Test 'program':
        python -m timeit -s '
                import mitogen.parent as p;
                import mitogen.master as m;
                r=m.Router();
                s=p.Stream(r, 0, max_message_size=1);
                r.broker.shutdown()'\
                \
                's.get_preamble()'
5 years ago
David Wilson d6c4a983e1 service: PushFileService never recorded a file as sent.
Ansible modules were being resent continuously - but only the main
script module, and any custom modutils if any were present.

Wire footprint drops by ~1/3rd for a 500 task run of 'shell: hostname':

-rw-r--r-- 1 root root 584K Jan 31 22:06 500mito-before2
-rw-r--r-- 1 root root 434K Jan 31 22:04 500mito-filesbugonly
5 years ago
David Wilson 7ca927608c parent: synchronize get_core_source()
Single task 100 SSH target run, before:

        3533181 function calls (3533083 primitive calls) in 616.688 seconds
        User time (seconds): 32.52
        System time (seconds): 2.71
        Percent of CPU this job got: 64%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:54.88

After:

        451602 function calls (451504 primitive calls) in 570.746 seconds
        User time (seconds): 29.48
        System time (seconds): 2.81
        Percent of CPU this job got: 67%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:48.20
5 years ago
David Wilson 2399a9e621 service: use correct profile aggregation name. 5 years ago
David Wilson c6d5aa29ba ansible: new multiplexer/workers configuration
Following on from 152effc26c9a5918cb7ead7a97fe7fa7f81b6764,

* Pin mux to CPU 0
* Pin top-level CPU 1
* Pin workers sequentially to CPU 2..n

Nets 19.5% improvement on issue_140__thread_pileup.yml when targetting
64 Docker containers on the same 8 core/16 thread machine.

Before (prior to last scheme, no affinity at all):

    2294528.731458      task-clock (msec)         #    6.443 CPUs utilized
        10,429,745      context-switches          #    0.005 M/sec
         2,049,618      cpu-migrations            #    0.893 K/sec
         8,258,952      page-faults               #    0.004 M/sec
 5,532,719,253,824      cycles                    #    2.411 GHz                      (83.35%)
 3,267,471,616,230      instructions              #    0.59  insn per cycle
                                                  #    1.22  stalled cycles per insn  (83.35%)
   662,006,455,943      branches                  #  288.515 M/sec                    (83.33%)
    39,453,895,977      branch-misses             #    5.96% of all branches          (83.37%)

     356.148064576 seconds time elapsed

After:

    2226463.958975      task-clock (msec)         #    7.784 CPUs utilized
         9,831,466      context-switches          #    0.004 M/sec
           180,065      cpu-migrations            #    0.081 K/sec
         5,082,278      page-faults               #    0.002 M/sec
 5,592,548,587,259      cycles                    #    2.512 GHz                      (83.35%)
 3,135,038,855,414      instructions              #    0.56  insn per cycle
                                                  #    1.32  stalled cycles per insn  (83.32%)
   636,397,509,232      branches                  #  285.833 M/sec                    (83.30%)
    39,135,441,790      branch-misses             #    6.15% of all branches          (83.35%)

     286.036681644 seconds time elapsed
5 years ago
David Wilson e77048ec2d utils: pad out reset_affinity() and integrate with detach_popen() 5 years ago
David Wilson b0e3807b16 utils: import reset_affinity() function. 5 years ago
David Wilson cafdfdb8e2 master: set Router.profiling if MITOGEN_PROFILING variable present. 5 years ago
David Wilson 568044438d parent: don't kill children when profiling is active. 5 years ago
David Wilson 5dc85c05f9 profiler: import from linear2 branch 5 years ago
David Wilson 960392cf50 core: tidy up existing profiling code and support MITOGEN_PROFILE_FMT 5 years ago
David Wilson 3606580f05 issue #260: redundant if statement. 5 years ago
David Wilson b8a0e0f929 master: cache sent/forwarded module names
On 32x Docker run of issue_140__thread_pileup.yml

Before:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   384807    3.595    0.000   12.207    0.000 /home/dmw/src/mitogen/mitogen/master.py:896(_forward_one_module)
  1218352    4.867    0.000    7.302    0.000 /home/dmw/src/mitogen/mitogen/master.py:853(_send_module_and_related)

After:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   384807    3.839    0.000    6.543    0.000 /home/dmw/src/mitogen/mitogen/master.py:902(_forward_one_module)
  1218352    0.723    0.000    0.898    0.000 /home/dmw/src/mitogen/mitogen/master.py:856(_send_module_and_related)
5 years ago
Alex Willmer 0d725f9cd8 Fix DeprecationWarning in mitogen.utils.run_with_router()
```
14:20:32.186270 W py.warnings:
/home/alex/src/mitogen/mitogen/utils.py:152: DeprecationWarning: invalid
escape sequence \*
  """
```
5 years ago
David Wilson 696cee57dd issue #260: hide force-disconnect messages.
Parent is always force-disconnected, and now it shows up quite visibly
on every exit.
5 years ago
David Wilson 26c6c6d048 issue #498: fix shutdown crash
Traceback (most recent call last):
      File "<stdin>", line 2707, in _invoke
      File "<stdin>", line 2480, in _on_del_route
    NameError: global name 'target_id' is not defined
5 years ago
David Wilson a18a083c94 issue #260: avoid start_transmit()/on_transmit()/stop_transmit()
Previous transmit sequence was:
        Router._async_route -> Stream._send -> Broker._start_transmit ->
        Broker.loop -> Stream.on_transmit -> socket.write ->
        Broker.stop_transmit

New sequence, when socket buffer can hold message is:
        Router._async_route -> Stream._send -> socket.write

bench/roundtrip.py
        Before: 240 usec
        after: 178 usec

Stat before:
       5088.276050      task-clock (msec)         #    0.997 CPUs utilized
           185,568      context-switches          #    0.036 M/sec
                 0      cpu-migrations            #    0.000 K/sec
            18,923      page-faults               #    0.004 M/sec
    13,063,871,501      cycles                    #    2.567 GHz
    12,834,579,684      instructions              #    0.98  insn per cycle
     2,669,820,684      branches                  #  524.700 M/sec
       107,296,033      branch-misses             #    4.02% of all branches

       5.105018296 seconds time elapsed

       2.350970000 seconds user
       0.345497000 seconds sys

Stat after:
       4019.208047      task-clock (msec)         #    0.998 CPUs utilized
           249,471      context-switches          #    0.062 M/sec
                 0      cpu-migrations            #    0.000 K/sec
            20,990      page-faults               #    0.005 M/sec
    10,312,535,979      cycles                    #    2.566 GHz
    11,586,365,995      instructions              #    1.12  insn per cycle
     2,392,933,370      branches                  #  595.374 M/sec
        75,432,205      branch-misses             #    3.15% of all branches

       4.028763347 seconds time elapsed

       3.367051000 seconds user
       0.652962000 seconds sys
5 years ago
David Wilson d4a0b70e15 core: ensure broker profiling output reaches disk
Profiler hasn't been used much since the hard exit was added.
5 years ago
David Wilson dc4b27c6bf master: keep is_stdlib_path() result as negative cache entry
On 32x Docker run of issue_140__thread_pileup.yml

Before:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
  1218500    1.716    0.000    7.325    0.000 /home/dmw/src/mitogen/mitogen/master.py:118(is_stdlib_path)

After:

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
      166    0.000    0.000    0.001    0.000 /home/dmw/src/mitogen/mitogen/master.py:123(is_stdlib_path)
5 years ago
David Wilson fca5513610 issue #429: fix sudo regression. 5 years ago
David Wilson 0c0d34241b core: Latch._wake improvements
os.write() can fail with EINTR due to signals, so wrap it in
io_op(). Closes #483.

Masking EBADF looks like it is/was almost certainly papering over a bug,
remove it and suffer the bug reports. Closes #495.
5 years ago
David Wilson 407294cd79 issue #498: prevent crash on double 'disconnect' signal.
Fixes:

ERROR! [pid 1096] 23:31:48.363215 E mitogen: _broker_main() crashed
Traceback (most recent call last):
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2917, in _broker_main
    self._loop_once()
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2875, in _loop_once
    self._call(side.stream, func)
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2860, in _call
    stream.on_disconnect(self)
  File "/home/dmw/src/mitogen/mitogen/parent.py", line 1161, in on_disconnect
    super(Stream, self).on_disconnect(broker)
  File "/home/dmw/src/mitogen/mitogen/core.py", line 1534, in on_disconnect
    fire(self, 'disconnect')
  File "/home/dmw/src/mitogen/mitogen/core.py", line 390, in fire
    func(*args, **kwargs)
  File "/home/dmw/src/mitogen/mitogen/parent.py", line 1794, in <lambda>
    func=lambda: self._on_stream_disconnect(stream),
  File "/home/dmw/src/mitogen/mitogen/parent.py", line 1810, in _on_stream_disconnect
    routes = self._routes_by_stream.pop(stream)
KeyError: mitogen.ssh.Stream('ssh.localhost:2236')
5 years ago
David Wilson 9aa845669c issue #413: don't double-propagate DEL_ROUTE to parent.
propagate_up() sends ADD_ROUTE and DEL_ROUTE

propagate_down() sends only DEL_ROUTE, but didn't bother checking if
up() had sent it already.

Fixes:

     ERROR! [pid 41060] 17:55:30.739159 E mitogen.ctx.ssh.localhost:
     mitogen: RouteMonitor(): received DEL_ROUTE for 6081 from
     mitogen.fork.Stream(u'fork.41142'), expected
     mitogen.core.Stream('parent')
5 years ago
David Wilson e2478dcb9f issue #498: wrap Router dict mutations in a lock 5 years ago
David Wilson 6e9f8e829e issue #429: teach sudo about every know i18n password string. 5 years ago
David Wilson ec789513dc ssh: tidy up logs and stream names. 5 years ago
David Wilson 16a2de65c4 issue #493: another Py3.x fix. 5 years ago
David Wilson 2a70b3d5f4 issue #493: Py3.x fix. 5 years ago
David Wilson bc84d1e950 issue #493: less CPU-intensive cookie format. 5 years ago
David Wilson 14d393765b issue #488: 2.4-compatible syntax in unix.py. 5 years ago
David Wilson be6ab52fe1 issue #488: fix shutdown damage caused in 6ca2677de5
os._exit() subverted calm shutdown, meaning unix.Listener never had a
chance to cleanup its socket.

Move unix.Listener socket cleanup into its class so it is automatic
during shutdown, rather than cutpasted for each consumer.

Disable the watcher thread in the MuxProcess, it is useless.

Add .sock extension to /tmp/mitogen_unix_*, so we can write a test.
5 years ago
David Wilson b370076689 issue #490: log mitogen.unix server-side accept. 5 years ago
David Wilson 7dae88f0f5 issue #490: have Side._on_fork() empty _fork_refs
This is mostly to avoid ugly debugging that depends on the state of GC.
Discard sides from _fork_refs after they have been closed.
5 years ago
David Wilson 3435f24e8d issue #479: ModuleFinder special case for __main__ on Py3.x. 5 years ago
David Wilson 4095358ea4 Merge commit '5bd6bd0' into envtest
* commit '5bd6bd0':
  parent: don't send messages on streams that no longer exist; closes #480
5 years ago
David Wilson 2b234936b8 core: docstring tidyups. 5 years ago
David Wilson f17fb91993 core: ensure early debug messages are logged correctly.
The magical _v and _vv were being set too late. Drag _setup_logging()
out of the Router constructor and call it at the right moment during
bootstrap.
5 years ago
David Wilson 8a931e79b0 core: log disconnection reason. 5 years ago
David Wilson d0075e7e50 parent: --with-pydebug bootstrap could fail due to corrupted stream
Due to first stage writin 'XXX refs' on exit. So close stderr as last
step of first stage.
5 years ago
David Wilson 137f5fa6c5 issue #477: add basic su_test and Py2.4 polyfill. 5 years ago
David Wilson 2e4d7b15d7 parent: don't kill child when profiling=True 5 years ago
David Wilson 29cb6cb4f8 issue #477: Py2.4 startswith() did not support tuples. 5 years ago
David Wilson 61297c24e5 issue #477: call_function_test fixes for 2.4. 5 years ago
David Wilson dd30a907ce issue #477: promote setup_gil() to mitogen.utils
This is since ansible_mitogen/process.py is 2.6-only, and I want to use
setup_gil() in 2.4 code.
5 years ago
David Wilson f1a712fad3 issue #477: Python<2.5 ioctl() request parameter was signed. 5 years ago
David Wilson 4ca3051e39 issue #477: document master.Router.max_message_size. 5 years ago
David Wilson a8716972fb issue #477: 2.4 stat() returned int timestamps not float. 5 years ago
David Wilson 19eafc5755 issue #477: set().union(a, b, ..) unsupported on Py2.4. 5 years ago
David Wilson e460d648d5 issue #477: Logger.log(extra=) unsupported on Py2.4. 5 years ago
David Wilson 1f59bcc313 issue #477: fix another Threading.getName() call. 5 years ago
David Wilson bd81b6fd6e issue #477: %f date format requires Py2.6 or newer. 5 years ago
David Wilson 6a2f88d6a3 issue #477: make mitogen.fork unsupported on Py<2.6. 5 years ago
David Wilson 112caa94f9 issue #477: Py2.4 dep scanner bytecode difference 5 years ago
David Wilson d6dcb8d010 issue #477: blacklist 'thread' module to avoid roundtrip on 2.x->3.x 5 years ago
David Wilson 4c1ddf6fc1 issue #477: Python3 does not have Pickler.dispatch. 5 years ago
David Wilson 7ecd5d8ba3 issue #477: ModuleFinder test fixes. 5 years ago
David Wilson 5bd6bd06d1 parent: don't send messages on streams that no longer exist; closes #480 5 years ago
David Wilson a31718a6bc issue #477: use PY24 constant rather than explicit test. 5 years ago
David Wilson bc434a4f99 issue #477: backport mitogen.master to Python 2.4. 5 years ago
David Wilson ffd46e9f1c issue #477: parent: make iter_read() log disconnect reason. 5 years ago
David Wilson 87d2af4c6e issue #477: polyfill partition() use in mitogen.parent. 5 years ago
David Wilson dd86a157ff issue #477: polyfill partition() use in mitogen.service. 5 years ago
David Wilson d6da84c38f issue #477: polyfill partition() use in mitogen.ssh. 5 years ago
David Wilson e9706a4a09 issue #477: _update_linecache() must append newlines. 5 years ago
David Wilson 19b708e141 issue #415, #477: Poller must handle POLLHUP too.
Linux will fire poll() with simply the POLLHUP bit set even though it
was not requested, resulting in an infinite loop.
5 years ago
David Wilson 07f1b9bdd0 issue #477: Python 2.5 needs next() polyfill too. 5 years ago
David Wilson 3afd667136 issue #477: explicitly populate Py2.4 linecache from Importer. 5 years ago
David Wilson 97a96f5dd8 issue #477: rename and add tests for polyfill functions. 5 years ago
David Wilson da13415b00 issue #477: various core.py docstring cleanups. 5 years ago
David Wilson 5135ff9068 issue #477: master: ability to override ModuleResponder output.
This is needed to cope Ansible 2.3 doing weird stuff as usual. It serves
up __init__.py for ansible and ansible.module_utils as hard-coded
namespace packages, the real ansible/__init__.py on disk is not 2.4
compatible.
5 years ago
David Wilson dd36450daf issue #477: yet another bug in core._partition(). 5 years ago
David Wilson d8490bc90a issue #477: 2.4.x compat fixes for mitogen.service. 5 years ago
David Wilson 58d8813c03 issue #477: Py2.4 lacks all(). 5 years ago
David Wilson 1f17422598 issue #477: make CallError serializable on 2.4.
Making CallError inherit from object broke 'raise CallError()'.

Instead use pure-Python pickler on 2.4 (grmbl) and force it to emit
new-style-alike output for what is otherwise a classic class.

Remove needless complexity from _unpickle_call_error() that only worked
for new-style classes.
5 years ago
David Wilson 4b89dc4813 issue #477: log full module name when SyntaxError occurs. 5 years ago
David Wilson d4afa102c7 issue #477: more Py2.4 (str|unicode).partition(). 5 years ago
David Wilson 0ee8ee78b8 issue #477: Py2.4 cannot tolerate unicode kwargs. 5 years ago
David Wilson 08cecb92f6 issue #477: Py2.4 lacks BaseException. 5 years ago
David Wilson 51a07dce70 issue #477: Py2.4: more unicode.rpartition() usage. 5 years ago
David Wilson 07401d767a issue #477: Python 2.4 type(exc) returns old-style instance. 5 years ago
David Wilson 3767d56187 issue #477: Python <2.5 did not have combined try/finally/except. 5 years ago
David Wilson 33caea06ed issue #477: Python <2.5 lacked any(). 5 years ago
David Wilson 3109abd518 issue #477: Python <2.6 lacked rpartition(). 5 years ago
David Wilson 84601f41fd issue #477: make CallError inherit from object for 2.4/2.5.
Otherwise cPickle will not call __reduce__().
5 years ago
David Wilson f3dae10fe1 issue #477: 2.4/2.5 had no better poller than poll(). 5 years ago
David Wilson 881dc7d5ca issue #477: more 2.4-compatible thread.get_ident() use. 5 years ago
David Wilson a1e0b4381f issue #477: bump corrupt msg output size to 2Kb
Allows much more of any tracebacks present to become visible.
5 years ago
David Wilson e99b8a8de7 core: replace ancient YOLO loop in fire(). 5 years ago
David Wilson 1119f24071 issue #414: reinitialize service pool lock on fork 5 years ago
David Wilson 120c667052 core: many docstring updates and an example substitute for Channel 5 years ago
David Wilson 84f75551a3 core: make Receiver a self-closing context manager. 5 years ago
David Wilson fcc403cc2f core: make Receiver.to_sender() use Router.myself(). 5 years ago
David Wilson bc0be45612 issue #61: unused import (reported by LGTM) 5 years ago
David Wilson 6da52ff00e issue #61: unused import (reported by LGTM) 5 years ago
David Wilson d63c99d912 issue #61: unused import (reported by LGTM) 5 years ago
David Wilson 00838e9134 issue #61: unused import (reported by LGTM) 5 years ago
David Wilson 96c35ccab1 issue #61: unused variable (reported by LGTM) 5 years ago
David Wilson 95fe052158 issue #61: unused import (reported by LGTM) 5 years ago
David Wilson fb750edfa7 issue #61: fix bare except (reported by LGTM) 5 years ago
David Wilson abfb6e39a8 issue #61: unused variable (reported by LGTM) 5 years ago
David Wilson 7bb6b4ab4b issue #61: remove duplicate method (reported by LGTM) 5 years ago
David Wilson 5bd9efb723 issue #61: add missing close() implementation (reported by LGTM) 5 years ago
David Wilson 767737265a issue #61: add inverse comparison (reported by LGTM) 5 years ago
David Wilson 51bd35280a issue #61: remove duplicated method (reported by LGTM) 5 years ago
David Wilson 06415bb720 issue #310: fix test failures, teach old import method new tricks
- don't try anything unless something really lives in sys.modules by
  that name
- non-ASCII files are possible
- the unimportable thing might be an extension module, we don't want
  that
5 years ago
David Wilson 6af1a64cce master: handle crazy non-modules in sys.modules again; closes #310. 5 years ago
David Wilson ea9ef50b3c issue #415: replace default Poller with select.poll()
30% latency reduction for IPC.
5 years ago
David Wilson fd90834944 issue #408: fix test fallout. 5 years ago
David Wilson 51ac309647 issue #408: 2.4 compat: replace iter_read with explicit generator
Can't use yield inside try/finally on 2.4.
5 years ago
David Wilson 41626b82dd issue #408: 2.4 compat: remove ternary if use in master.py. 5 years ago
David Wilson 5b45b5851c issue #408: use compatible method to get thread ID. 5 years ago
David Wilson 3aff3e5506 issue #408: fix mitogen.compat.tokenize 2.4 compatibility. 5 years ago
David Wilson a8c056c27b issue #436: decode debug log lines on Python 3. 5 years ago
David Wilson 5761652e02 core: allow Router.shutdown() to succeed after exit.
For join_thread():

Exception in thread mitogen.master.join_thread_async:
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/home/dmw/src/mitogen/mitogen/master.py", line 249, in _watch
    watcher.on_join()
  File "/home/dmw/src/mitogen/mitogen/master.py", line 816, in shutdown
    super(Broker, self).shutdown()
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2741, in shutdown
    self.defer(_shutdown)
  File "/home/dmw/src/mitogen/mitogen/core.py", line 2142, in defer
    raise Error(self.broker_shutdown_msg)
Error: An attempt was made to enqueue a message with a Broker that has already exitted. It is likely your program called Broker.shutdown() too early.
5 years ago
David Wilson 822978520f issue #446: update Receiver.__iter__ to match
iter() previously relied on the fake dead message being enqueued.
5 years ago
David Wilson 57b652eddc parent: remove unused imports
The stray functools import must have been there forever! Instant 4kb
knocked off wire footprint.
5 years ago
David Wilson 5ef94eb3e2 issue #456: loosen Waker.defer() shutdown test a little
Allow messages to continue being queued during the shutdown period,
right up until the final loop iteration, even though this is racy, as
too many things depend on .defer() during exit right now.

This doesn't hurt the spirit of the check: it still catches the worst
situation where $user accidentally shut down Broker then tried to
continue using it.
5 years ago
David Wilson cce1dbf3b1 tests: quieten a bunch of spam printed during run 5 years ago
David Wilson b6840aab75 issue #459: one line stats output during shutdown
CI logs are too noisy.
5 years ago
David Wilson 3b17cb7c5b unix: add Listener.__repr__. 5 years ago
David Wilson bcd9827c3b core: Latch.empty() improvements
- throw LatchError if the latch is closed.
- wrap with the lock to avoid unexpected weirdness.
5 years ago
David Wilson 388649df97 core: Receiver.close() now wakes all threads; closes #446. 5 years ago
David Wilson f2f41809ae issue #459: initial get_stats() implementation 5 years ago
David Wilson 1d97493fcd tests: fallout from #447. 5 years ago
David Wilson ab8d6afbae core: use ModuleNotFoundError in imporer if it is available; closes #448. 5 years ago
David Wilson de719fa249 core: throw error on duplicate add_handler(); closes #447. 5 years ago
David Wilson dc92e529bc service: unregister receiver at shutdown; closes #445. 5 years ago
David Wilson 85e965118d Merge remote-tracking branch 'origin/issue462'
* origin/issue462:
  issue #462: docs: update Changelog.
  parent: cope with broken /dev/pts on Linux; closes #462.
5 years ago
David Wilson 04755c3321 issue #426: tighten up PushFileService types.
Bytes/Unicode mixing caused a hang, so prevent bytes entirely.
5 years ago
David Wilson 8fa3c74de4 issue #426: RouterMonitor format incorrect for 3->2 forward.
Each hop would cause "b''" to be wrapped around the context name.
5 years ago
David Wilson d8b9634c85 issue #426: PushFileService missing to_text() call. 5 years ago
David Wilson a4c7a98dd9 parent: cope with broken /dev/pts on Linux; closes #462. 5 years ago
David Wilson 2f3a8f2a32 parent: proxy_connect docstring. 5 years ago
David Wilson ec056042e0 core: more Poller docstrings. 5 years ago
David Wilson d286eeb2ea core: more Poller docs 5 years ago
David Wilson 5f5396bcb2 core: more poller doc 5 years ago
David Wilson 499e7273d1 core: poller tidyups and minify fix 5 years ago
David Wilson 3f5774cfd5 core: document/tidy up poller.
Remove duplicate attribute creates in subclasses too.
5 years ago
David Wilson a156d7aab3 core: move importer inline data out to class vars. 6 years ago
David Wilson 824c7931a9 core: improve importer exception messages. 6 years ago
David Wilson 1eb08fb5c5 core: docstring tidyups 6 years ago
David Wilson 81a68223d4 issue #456: exception text typo. 6 years ago
David Wilson 497234e782 issue #456: core: raise error during defer() if Broker shutdown 6 years ago
David Wilson 917a1ffb29 issue #453: prevent accidental child logging loop. 6 years ago
David Wilson 6713b90acc FileService: exceptions must be sent explicitly for no-reply methods
FileService should not be using no-reply at all.
6 years ago
David Wilson 98696af9f8 service: log failing path in FileService call. 6 years ago
David Wilson 2bbab585f7 service: fix NameError during no-reply call on 3.x. 6 years ago
David Wilson 9680a84824 core: rename Router.self() to Router.myself(). 6 years ago
David Wilson 8f85ee038e core: Add Router.self()
Returns a reference to the current context.
6 years ago
David Wilson f20e0bbac1 service: Allow registering path prefixes with FileService.
e.g. service.register_prefix('/') disables all security checks.
6 years ago
David Wilson 6fafc0a631 select: Python 2.x required __nonzero__ for bool(Select) 6 years ago
David Wilson d030decf57 issue #444: master: lower log level for soft import error. 6 years ago
David Wilson 300cb41e2e core: detect stream corruption. Closes #438. 6 years ago
David Wilson 3876590aa1 parent: add descriptive errors for unsupported call() types.
Closes #439.
6 years ago
David Wilson c2c7caa34f core: ignore DeprecationWarning for imp module.
Closes #399, #437.
6 years ago
David Wilson fbd7346d02 examples: import the_basics.py. 6 years ago
David Wilson 15ddecdb58 issue #391: FileService metadata dict keys must be Unicode.
This is a regression since moving FileService from a 2.6-compatible file
with unicode_literals set, to a <2.5-compatible file.
6 years ago
David Wilson 57504ba6ec issue #109: core: meta_path regression in newer Pythons
Python at some point (at least since https://bugs.python.org/issue14605)
began populating sys.meta_path with its internal importer classes,
meaning that interpreters no longer start with an empty sys.meta_path.
6 years ago
David Wilson 2a2dda8e39 issue #364: remove stat() caching. 6 years ago
David Wilson 4267014ca6 issue #364: clarify logged error when incorrect file size detected 6 years ago
David Wilson 65d9eec353 issue #364: core: have Sender.close() supply reason= to dead() 6 years ago
David Wilson 01c4f3fee1 core: rearrange stdio setup to cope with buffering; closes #422 6 years ago
David Wilson de7d4e0908 setns: decode utility command output for 3.x. 6 years ago
David Wilson c7931be524 issue #420: core: include PID in Latch cookie data. 6 years ago
David Wilson 6d5facec4c su/sudo: fallout from previous commits
issue #418 and FD cleanup work.
6 years ago
David Wilson 045db6f689 Fix iter_read() FD leaks on 3.x; closes #418. 6 years ago
David Wilson 6e1f9e2596 core: 2.6 str.decode() compat fix. 6 years ago
David Wilson 76ec4f201c issue #413: paper over harmless duplicate del_route()
Ideally it would only be called once, and in future maybe it can, but
right now we need to cope with these cases:

* Downstream parent notifies us of disconnection (DEL_ROUTE)
* We notify ourself of disconnection
* We notify ourself and so does downstream parent

It's case 3 that causes the error.
6 years ago
David Wilson cf97932fad core: dead messages have optional body, use it everywhere; closes #387. 6 years ago
David Wilson c09780aeb0 core: fix add_handler(respondent=..) memory leak
Closes #416.
6 years ago
David Wilson 802de6a8d5 issue #406: clean up DiagLogStream handling and connect() failure.
When Stream.connect() fails, have it just use on_disconnect(). Now there
is a single disconnect cleanup path.

Remove cutpasted DiagLogStream setup/destruction, and move it into the
base class (temporarily), and only manage the lifetime of its underlying
FD via Side.close().  This cures another EBADF failure.
6 years ago
David Wilson 586c6aca9a issue #406: unix: fix ordering of stop_receive/close. 6 years ago
David Wilson 661e274556 issue #406: ensure is_path_dead() socket is finalized. 6 years ago
David Wilson 411af6c167 issue #406: unix: don't leak already-closed socket object
if Side.close() closes the socket (which it does), and it gets reused,
GC will cause socketobject.__del__ to later delete some random FD.
6 years ago
David Wilson dc3db49c5a issue #406: more leaked FDs when create_child() fails. 6 years ago
David Wilson 17631b0573 issue #406: parent: close extra_fd on failure too. 6 years ago
David Wilson b3841317dd issue #406: clean up FDs on failure explicitly
The previous approach was crap since it left e.g. socketpair instances
lying around for GC with their underlying FD already closed, coupled
with FD number reuse, led to random madness when GC finally runs.
6 years ago
David Wilson 10af266678 issue #406: attempt Broker cleanup in case of a crash. 6 years ago
David Wilson 375182b71b issue #406: don't leak side FDs on bootstrap failure. 6 years ago
David Wilson 14b389cb46 issue #406: don't leak FDs on failed child start. 6 years ago
David Wilson d1c2e7a834 issue #406: call Poller.close() during broker shutdown. 6 years ago
David Wilson e4280dc14a core: Don't crash in Waker.__repr__ if partially initialized. 6 years ago
David Wilson 87e8c45f76 core: fix minify_test regression introduced in 804bacdadb
The minifier can't handle empty function bodies, so the pass statements
are necessary.
6 years ago
David Wilson 16c364910a core: avoid redundant write() calls in Waker.defer()
Using _lock we can know for certain whether the Broker has received a
wakeup byte yet. If it has, we can skip the wasted system call.

Now on_receive() can exactly read the single byte that can possibly
exist (modulo FD sharing bugs -- this could be improved on later)
6 years ago
David Wilson 8e4c164d93 issue #388: fix Sphinx markup 6 years ago
David Wilson 804bacdadb docs: move most remaining docstrings back into *.py; closes #388
The remaining ones are decorators which don't seem to have an autodoc
equivlent.
6 years ago
David Wilson 711aed7a4c core: split _broker_shutdown() out into its own function.
Makes _broker_main() logic much clearer.
6 years ago
David Wilson 1d32ed3b5a core: avoid shutdown() in IoLogger on WSL; closes #333. 6 years ago
David Wilson 07fefa4067 kubectl: paper over importer issue by removing unicode. 6 years ago
David Wilson 5be9a55bf4 core: allow Context to be pickled by non-Mitogen pickler. 6 years ago
David Wilson f2d288bb1e tests: ensure minify() result can be compiled for all of core. 6 years ago
David Wilson a7ee23719a issue #388: move a ton of documentation back into the source 6 years ago
David Wilson fadb9181bc issue #410: support sudo --user and SELinux options, add stub test. 6 years ago
David Wilson 0394dac2c7 docs: document RouteMonitor class. 6 years ago
David Wilson 71f9e84ab3 Add EOF error hints for LXC/LXD; closes #373. 6 years ago
David Wilson 22b4b186d7 issue #333: add versioning to EpollPoller too. 6 years ago
David Wilson 73cda2994f issue #333: add versioning, initial batch of poller tests
Now poller is start enough to know a start_receive() during an iteration
does not cause events yielded by that iteration to associate with the
wrong descriptor.

These changes are tangentially related to the associated ticket, but
event versioning is still the underlying issue.
6 years ago
David Wilson 1cbff1011e core: send dead message if max message size exceeded; closes #405 6 years ago
David Wilson 1eae594e32 ssh: fix check_host_keys="accept" and test; closes #411
Add real accept/enforce tests.
6 years ago
David Wilson 16ca111ebd ssh: better OpenSSH 7.5+ permission denied handling
The user@host prefix in new-style OpenSSH messages unfortunately takes
the host part from ~/.ssh/config and friends. There is no way to know
which hostname will appear in this string without parsing the OpenSSH
config, nor which username will appear.

Instead just regex it.

Add SSH stub modes to print the new/old errors and add some simple
tests.

This extends the work done in b9112a9cbb
6 years ago
David Wilson 9ec360c26d core: split out & extend Broker.sync_call() 6 years ago
David Wilson f343bbba3a unix: fix exception catch on 3.x. 6 years ago
David Wilson 0d04e940b7 master: docstring fixes. 6 years ago
David Wilson 4e3830d75e tests: add basic unix_test.py. 6 years ago
David Wilson 58d0a45738 issue #76: quieten routing errors.
Receiving DEL_ROUTE without a corresponding ADD_ROUTE is now legit
behaviour, so don't print an error in this case.

Don't print an error for dropped messages if the reply_to indicates the
sender doesn't care about a response (dead and no_reply)
6 years ago
David Wilson fba52a0edf issue #76: add API for ansible_mitogen to get route list
Earlier commit moved Stream.routes attribute into a private map
belonging to RouteMonitor, to make upgrades smoother. This adds a new
accessor method to RouteMonitor.
6 years ago