Commit Graph

57 Commits (6bd8fda1d4d3fec781dfcad509d3614285d1a8e5)

Author SHA1 Message Date
David Wilson fd5e962cb3 Handlers no longer depend on src_id
Now there is a single handle namespace in each context, indpendent of
the source of the message. Update module forwarder etc. to cope with
that.

This is to support slave contexts communicating without the master's
intercession.
7 years ago
David Wilson 9ed7934994 Shorten slave context logger name. 7 years ago
David Wilson c37a11fb99 Add Router.local() mostly for testing. 7 years ago
David Wilson 30d838edf9 Add econtext.master.Context.call_async(). 7 years ago
David Wilson 6a164adb22 Preserve sys.executable after first stage. 7 years ago
David Wilson 7a50fa724e Defer stream naming until after connect, so PID can be included. 7 years ago
David Wilson 4b2170dc81 Wire up ModuleForwarder; closes #3 7 years ago
David Wilson e8b1ebc434 issue #3: Teach core.py the difference between its parent context and the master context.
Needed to allow GET_MODULE calls to reach the parent rather than the
master, when they are not the same context.
7 years ago
David Wilson 821c9dfcb6 Generalize ECONNRESET, EIO handling. 7 years ago
David Wilson 17c2fe68f2 Add Router.enable_debug() rather than cutpasting snippets constantly. 7 years ago
David Wilson a76d871a70 issue #3: Initial ModuleForwarder implementation.
Not wired up yet.
7 years ago
David Wilson fcd3f42f9e Quieten noisy logging 7 years ago
dmw 92a4a61f11 Generate context IDs like handles. 7 years ago
David Wilson f9df857a57 Tidy up API. 7 years ago
David Wilson 4969d7ba61 Fix various bits of bad logging and hard-wired timeouts. 7 years ago
David Wilson 0d0c87f910 Get routing working well. 7 years ago
David Wilson 0a0a060492 Introduce econtext.core.Router, refactor everything
* Header now contains (src, dst) context IDs for routing.
* econtext.context_id now contains current process' context ID.
* Now do 16kb-sized reads rather than 4kb.
* econtext package is uniformly imported in econtext/core.py in slave
  and master.
* Introduce econtext.core.Message() to centralize pickling policy, and
  various function interfaces, may rip it out again later.
* Teach slave/first stage to preserve the copy of econtext.core sent to
  it, so that it can be used for subsequent slave-of-slave bootstraps.
* Disconnect Stream from Context, and teach Context to send messages via
  Router. In this way the Context class works identically for slaves
  directly connected via a Stream, or those for whom other slaves are
  acting as proxies.
* Implement Router, which knows a list of contexts reachable via a
  Stream. Move context registry out of Broker and into Router.
* Move _invoke crap out of stream and into Context.
* Try to avoid pickling on the Broker thread wherever possible.
* Delete connection-specific fields from Context, they live on the
  associated Stream subclass now instead.
* Merge alloc_handle() and add_handle_cb() into add_handler().
* s/enqueue/send/
* Add a hacky guard to prevent send_await() deadlock from Broker thread.
* Temporarily break shutdown logic: graceful shutdown is broken since
  Broker doesn't know about which contexts exist any more.
* Handle EIO in iter_read() too. Also need to support ECONNRESET in here.
* Make iter_read() show last 100 bytes on failure.
* econtext.master.connect() is now econtext.master.Router.connect(),
  move most of the context/stream construction cutpaste into a single
  function, and Stream.construct().
* Stop using sys.executable, since it is the empty string when Python
  has been started with a custom argv[0]. Hard-wire python2.7 for now.
* Streams now have names, which are used as the default name for the
  associated Context during construction. That way Stream<->Context
  association is still fairly obviously and Stream.repr() prints
  something nice.
7 years ago
David Wilson e374f85888 Fix module loader deadlock
Stop using cPickle on the broker thread where it is not known whether
the pickle data would cause the import machinery to be invoked, which
currently relies on blocking calls. Huge mess but it works.

This is due to:

        context.call(some.module.func, another.module.func)

We stringify ("some.module", "func"), but the reference to
another.module.func is passed into the pickle machinery, and there's no
way to generically stringify all function references in user data for
reification on the main thread, without doing something like this
instead.
7 years ago
David Wilson f3cf9a5501 Format string error. 8 years ago
David Wilson 6c8be56c63 Move write_all() to where it's used. 8 years ago
David Wilson 358e753010 Don't keep buffer of all previously received data. 8 years ago
David Wilson 99a2ccf68c First draft of econtext/sudo.py. 8 years ago
David Wilson 9733668b50 Replace OK indicator with EC0/EC1. 8 years ago
David Wilson fe171cd8cf Parameterize create_child() in order to support non-pipe children. 8 years ago
David Wilson 959839cbbf Fix log message. 8 years ago
David Wilson bdc2f291ca Some importers don't implement all the optional interfaces. 8 years ago
David Wilson ff903b1bcd Rearrange docs, split connection methods into submodules. 8 years ago
David Wilson 81dd265c20 Catch BaseException to cope with KeyboardInterrupt and suchlike.
Django's module autoreloader calls sys.exit(), we want to catch that.
8 years ago
David Wilson 30991a6b42 Cure flake8 error. 8 years ago
David Wilson d2829259a5 Python 3 compatible first stage. 8 years ago
David Wilson e4efcd9455 Don't do bool(source) as some modules are 0 bytes. 8 years ago
David Wilson 301972bc57 Restructure module importer to cope with Ansible. 8 years ago
David Wilson 5ccf90702e Use sys.executable for LocalStream.python_path by default
But still use just 'python' for SshStream.
8 years ago
David Wilson d4478ca25c Don't use minimize_source() on third party code.
It breaks at least indentation.
8 years ago
David Wilson 9d6d342af1 Add CallError to the permitted classes list. 8 years ago
David Wilson 3de06ca559 "Ansible compatible" module loader.
Since all Ansible modules ever written are using worst practice Python,
the module loader must be rewritten to cope with their horrors.

Ansible is woeful software:

* AnsibleModule argument declarations appear within the main() function,
  so they can't be introspected prior to execution.

* No if __name__ == '__main__' guard means they can't be introspected
  without triggering execution.

* By default the main() function attempts to read from stdin, hanging
  our IO thread.

* So much unspeakable crap.

This rewrites the module loader to avoid actually running a module if it
can possibly be avoided. The downside is that the new loader must be
aware of far more details of the Python module mechanism. For example
with the new importer, namespace packages are broken at the very least.

On the plus side, now the module loader will be able to cope with
Django.
8 years ago
David Wilson ec21caa098 IOLOG re. 8 years ago
David Wilson ba3a0b6c48 Fix line numbers. 8 years ago
David Wilson fea12a6030 Many updates: graceful shutdown, docs, threading
* Start splitting docs up into internals.rst / api.rst
* Docs for lots more of econtext.core.
* Get rid of _update_stream() and has_output(), replace with individual
  functions called as state changes.
* Add Broker.on_thread() and remove Stream._lock: simply call
  on_thread() to ensure buffer management is linearized.
* Rename read_side/write_side to receive_side/transmit_side like event
  handler names.
* Clean up some more repr / debug logs.
* Move handle cleanup to Context.on_shutdown where it belongs.
* Make wake() a noop when called from broker thread.
* Replace graceful_count crap with Side.graceful attribute, add
  Broker.keep_alive() to check whether any registered readers want to
  be kept alive for graceful shutdown() or any child contexts with a
  connected stream exist.
* Make master.Broker timeout slightly longer than slave broker.
* Add generic on_thread() to allow running code on the IO thread.
8 years ago
David Wilson f88b0a11e9 Python 2.4 fixes. 8 years ago
David Wilson 1f27872eda Many docs updates. 8 years ago
David Wilson 95902d94b0 Python 2.5 fix: Logger.getChild() does not exist there. 8 years ago
David Wilson da4e457247 More docs, move call/call_with_deadline to econtext.master. 8 years ago
David Wilson 62520b1bcb Write history section. 8 years ago
David Wilson ce27058bdf Initial intro doc. 8 years ago
David Wilson cc18ab5e28 Tidy up event names and docstrings. 8 years ago
David Wilson d6d13ee506 Rationalize _fixup_package(), fix _setup_master() name. 8 years ago
David Wilson 0e58a48611 Fix method naming everywhere. 8 years ago
David Wilson 70c2032bb2 Another hackish graceful shutdown method. 8 years ago
David Wilson 9a8fc5e167 Another attempt at graceful shutdown. 8 years ago