From 526590027afce04193ea329ea44f19efb8bbaaed Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 9 Jun 2018 22:07:59 +0100 Subject: [PATCH] issue #186: PushFileService improvements. New method to send all modules and files in one roundtrip. --- mitogen/service.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mitogen/service.py b/mitogen/service.py index 424f21c8..1bd426d1 100644 --- a/mitogen/service.py +++ b/mitogen/service.py @@ -590,6 +590,7 @@ class PushFileService(Service): finally: self._lock.release() + LOG.debug('%r.get(%r) waiting for uncached file to arrive', self, path) latch.get() LOG.debug('%r.get(%r) -> %r', self, path, self._cache[path]) return self._cache[path] @@ -614,6 +615,22 @@ class PushFileService(Service): context=context ).close() + @expose(policy=AllowParents()) + @arg_spec({ + 'context': mitogen.core.Context, + 'paths': list, + 'modules': list, + }) + def propagate_paths_and_modules(self, context, paths, modules): + """ + One size fits all method to ensure a target context has been preloaded + with a set of small files and Python modules. + """ + for path in paths: + self.propagate_to(context, path) + for fullname in modules: + self.router.responder.forward_module(context, fullname) + @expose(policy=AllowParents()) @arg_spec({ 'context': mitogen.core.Context, @@ -649,7 +666,7 @@ class PushFileService(Service): self, path, data, context) waiters = self._store(path, data) if context.context_id != mitogen.context_id: - self._forward(path, context) + self._forward(context, path) for callback in waiters: callback()