Commit Graph

66 Commits (a35fcf44cc2479e9f3f77b9d99138de6b53000ec)

Author SHA1 Message Date
David Wilson a35fcf44cc ansible: restructure to avoid intermediate imports 6 years ago
David Wilson f3e51a7b18 core: CALL_FUNCTION should check auth_id, not src_id 6 years ago
David Wilson 32f6ee7d43 issue #40: mitogen.unix initial implementation. 6 years ago
David Wilson e63e9d299e docs: add Message documentation 6 years ago
David Wilson 10230f62dd core: Message.reply() helper function 6 years ago
David Wilson 6fc8fa5b22 core: Don't crash if a stream is missing a side. 6 years ago
David Wilson 9238e09ae8 core: Restore behaviour of unpickling Router-specific Context subclass 6 years ago
David Wilson dd088908df select: clean up API. 6 years ago
David Wilson df07e47d24 core: de-munge Message.unpickle() vs. Receiver.get(). 6 years ago
David Wilson a39cd44bf2 core: add auth_id field. 6 years ago
David Wilson a54c96faae core: remove unused SecurityError. 6 years ago
David Wilson 07d4d799f1 Add mitogen.main() decorator mainly for docs and demo use. 6 years ago
David Wilson 55c23e1c57 issue #68: replace sets with lists
Fix a MyPy warning by only passing lists to select.select(). At least on
Python 2.x, select.select() was internally converting the sets to lists
anyway.

By the time lists become inefficient here, it is likely that
select.select() itself will also be inefficient, and need replaced with
.poll() or similar.

No discernible performance different when transferring django.db.models
to a local VM.
6 years ago
David Wilson a0d9d34231 core: fix profiling
* SIGTERM safety net prevents profiler from writing results, so disable
  it when profiling is active.
* fix warning corrupting stream when profiling=True
6 years ago
David Wilson 5f2fa2cda6 importer: always refuse builtins and __builtin__. 6 years ago
David Wilson 0f899f34ff importer: new format to signal ImportError
Previously we'd send just None in GET_MODULE reply, but now since there
is no single request-reply structure, we must include the fullname in
the LOAD_MODULE response and make all of its data fields None to
indicate the same.
6 years ago
David Wilson 4d01dc3ba6 Initial pass at module preloading
* Don't implement the rules for when preloading occurs yet
* Don't attempt to streamily preload modules downstream while this
  context hasn't yet received the final module. There is quite
  significant latency buried in here, but for now it's a lot of work to
  fix.

This works well enough to handle at least the mitogen package, but it's
likely broken for anything bigger.
6 years ago
David Wilson ed71ae72f8 master: make mitogen minimally functional under gevent
It seems gevent automatically sets blocking behaviour on fds produced by
the socket module, which causes the Python process we fork to fail
horribly. So in the child, always reset the blocking flag.
6 years ago
David Wilson 326886832e Add license text everywhere. 6 years ago
Alex Willmer 3831ac360f Replace all calls to file() with open()
Although these are synonyms in Python 2.x, when using MyPy to typecheck
code use of file() causes spurious errors.

This commit also serves as one small step to Python 3.x compatibility,
since 3.x removes the file() builtin.
6 years ago
David Wilson 0481c08beb Ensure _run_defer() fully executes at least once before shutdown
Without this, it's possible for Waker to be start_received() after the
shutdown signal has already been sent, resulting in 5 second delay
during shutdown.

Additionally mask EBADF during os.write() to waker's write side.
Necessary since nothing synchronizes writer threads from the broker
thread during shutdown. Could be done with a lock instead, but this is
cheaper.
6 years ago
David Wilson b1ad04330b docs: move Router.route() into Sphinx. 6 years ago
David Wilson fb759f7c16 docs: move Broker docstrings into Sphinx. 6 years ago
David Wilson ffa063cc01 docs: annother barriage of cross-reference fixes. 6 years ago
David Wilson 7f3a58d514 core: Remove unused on_shutdown attribute. 6 years ago
David Wilson ec66152e37 docs: better io_op doc, move Side docs to Sphinx. 6 years ago
David Wilson 0767abf26f docs: move BasicStream docs into Sphinx. 6 years ago
David Wilson b7a9aa46cf core: More robust shutdown
Now there is a separate SHUTDOWN message that relies only on being
received by the broker thread, the main thread can be hung horribly and
the process will still eventually receive a SIGTERM.
6 years ago
David Wilson 3285fc2f75 Implement test_aborted_on_local_context_disconnect 6 years ago
David Wilson 690ee6dbe2 Fix select_test failure, remove crap old timing_test. 6 years ago
David Wilson 2454dcc990 core: loosen assertion to allow fakessh_test to succeed. 6 years ago
David Wilson 9b13a4cc61 Fix 2 call_function_test failures. 6 years ago
David Wilson f1d82c7284 More API documentation. 6 years ago
David Wilson b7f95e558f Better document Router API and constructors. 6 years ago
David Wilson 815f23bddd Sense of block= parameter was inverted. 6 years ago
David Wilson c4d9f124c6 Document Sender and Receiver classes. 6 years ago
David Wilson 849ccebe04 receiver: only permit one notify callback
There is no point spamming a list for every function call, there is no
use case where multiple notify callbacks would be useful.
6 years ago
David Wilson 48bf987570 issue #20: fix queue.get() parameter list. 6 years ago
David Wilson e3d967ebeb issue #20: initial implementation of mitogen.master.Select(). 6 years ago
David Wilson 14783c75e8 issue #9: log warning when a cross-sibling CALL_FUNCTION occurs
First step to making it a fatal error.
6 years ago
David Wilson 9de1fca3bf issue #9: ensure messages arrive on the expected stream
If no ADD_ROUTE message has been received from the master associating a
stream with a particular context ID, then it is expected messages
originating from that context ID can only be routed via the parent.
6 years ago
David Wilson 01729b18a5 core: use an output deque rather than string to improve worst case perf
This probably worsens performance in the common case, but it prevents
runaway producers (see e.g. issue #36) from spending all their CPU
copying around huge strings.

It's also a small step towards a solution to issue #6, which will
replace the output buffer with some sort of fancier queue anyway.

This reduces a particular 40 second run of rsync to 1.5 seconds.
6 years ago
David Wilson effe4117e1 Treat EPIPE as disconnect too; needed for fakessh. 6 years ago
David Wilson 9c4bf37cfc Remove final vestiges of context.key. 6 years ago
David Wilson 05cc74d142 core: Support profiling 6 years ago
David Wilson a9387b0504 core: remove pointless eval() of ARGV0 environment variable. 6 years ago
David Wilson fb9ce1054c core: set O_NONBLOCK on every side. Closes #33
The last time I tested set_nonblock() as a fix for the rsync hang, I
used F_SETFD rather than F_SETFL, which resulted in no error, but also
did not set O_NONBLOCK. Turns out missing O_NONBLOCK was the problem.

The rsync hang was due to every context blocking in os.write() waiting
for either a parent or child buffer to empty, which was exacerbated by
rsync's own pipelining, that allows writes from both sides to proceed
even while reads aren't progressing. The hang was due to os.write() on a
blocking fd blocking until buffer space is available to complete the
write. Partial writes are only supported when O_NONBLOCK is enabled.
6 years ago
David Wilson 7a60b20dc6 core: Generalize/duplicate the call/send_await code using Receiver. 6 years ago
David Wilson e4c832685d core: synchronize Stream._output_buf by deferring send()
Previously _output_buf was racy. This may or may not be cheaper than
simply using a lock, but it requires much less code, so I prefer it for
now.
6 years ago
David Wilson ead67de883 core: make Side.write() return None rather than crash if side already closed. 6 years ago