examples: more comments.

pull/180/head
David Wilson 7 years ago
parent 9eccfb4972
commit 76ac49dbdc

@ -57,9 +57,9 @@ class Process(object):
def child_main(sender, delay): def child_main(sender, delay):
""" """
Executed on the main thread of the Python interpreter running on the target Executed on the main thread of the Python interpreter running on each
machine, using context.call() by the master. It simply sends the output of target machine, Context.call() from the master. It simply sends the output
the UNIX 'ps' command at regular intervals toward a Receiver on master. of the UNIX 'ps' command at regular intervals toward a Receiver on master.
:param mitogen.core.Sender sender: :param mitogen.core.Sender sender:
The Sender to use for delivering our result. This could target The Sender to use for delivering our result. This could target
@ -102,6 +102,9 @@ def parse_output(host, s):
class Painter(object): class Painter(object):
"""
This is ncurses (screen drawing) magic, you can ignore it. :)
"""
def __init__(self, hosts): def __init__(self, hosts):
self.stdscr = curses.initscr() self.stdscr = curses.initscr()
curses.start_color() curses.start_color()
@ -219,15 +222,15 @@ def main(router):
# Finally invoke the function in the remote target. Since child_main() # Finally invoke the function in the remote target. Since child_main()
# is an infinite loop, using .call() would block the parent, since # is an infinite loop, using .call() would block the parent, since
# child_main() never returns. Instead use .call_async(), which returns # child_main() never returns. Instead use .call_async(), which returns
# another Receiver. We also want to wait for results from receiver -- # another Receiver. We also want to wait for results from it --
# even child_main() never returns, if there is an exception, it will be # although child_main() never returns, if it crashes the exception will
# delivered instead. # be delivered instead.
call_recv = host.context.call_async(child_main, sender, delay) call_recv = host.context.call_async(child_main, sender, delay)
call_recv.host = host call_recv.host = host
# Adding call_recv to the select will cause CallError to be thrown by # Adding call_recv to the select will cause mitogen.core.CallError to
# .get() if startup in the context fails, halt master_main() and cause # be thrown by .get() if startup of any context fails, causing halt of
# the exception to be printed. # master_main(), and the exception to be printed.
select.add(call_recv) select.add(call_recv)
hosts.append(host) hosts.append(host)

Loading…
Cancel
Save