From 58102c81791779934164b1835b391e18be679709 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sat, 7 Oct 2017 17:43:09 +0530 Subject: [PATCH] docs: waiting on multiple calls --- docs/getting_started.rst | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/docs/getting_started.rst b/docs/getting_started.rst index b17b2b0c..23008f55 100644 --- a/docs/getting_started.rst +++ b/docs/getting_started.rst @@ -214,6 +214,17 @@ Let's try running it: Waiting On Multiple Calls ------------------------- +Using :meth:`Context.call_async` it is possible to start multiple function +calls then sleep waiting for responses as they are available. This makes it +trivial to run tasks in parallel across processes (including remote processes) +without the need for writing asynchronous code:: + + hostnames = ['host1', 'host2', 'host3', 'host4'] + contexts = [router.ssh(hostname=hn) for hn in hostnames] + calls = [context.call(my_func) for context in contexts] + + for recv, (msg, data) in mitogen.master.Select(calls): + print 'Reply from %s: %s' % (recv.context, data)