def main():

    # Create python Events for when worker1 and worker2 are ready.
    ready1 = threading.Event()
    ready2 = threading.Event()

    # These callbacks are called when messages are received from
    # worker1 and worker2. Note that these functions are called
    # in their own thread.

    def check_ready1(tuple):
        if tuple == 'ready':
            print('Worker1 reports ready')
            ready1.set()

    def check_ready2(tuple):
        if tuple == 'ready':
            print('Worker2 reports ready')
            ready2.set()

    # Set up a transport called "boss"
    t = Transport('boss')

    # Listen for messages from workers
    t.subscribe('worker1', check_ready1)
    t.subscribe('worker2', check_ready2)

    # Repeat forever
    while True:

        # Set both workers as not ready.
        ready1.clear()
        ready2.clear()

        print('\nWaiting for workers to be ready')

        # Wait for both workers to have indicated that they're ready.
        # Note that the order doesn't matter. If 2 is ready first, it
        # will remain ready until 1 is also ready.

        ready1.wait()
        ready2.wait()
        
        print('Both workers ready. Telling them to GO!')
        t.send('worker1', 'GO!')
        t.send('worker2', 'GO!')
Example #2
0
def main():

    # Create python Events for when worker1 and worker2 are ready.
    ready1 = threading.Event()
    ready2 = threading.Event()

    # These callbacks are called when messages are received from
    # worker1 and worker2. Note that these functions are called
    # in their own thread.

    def check_ready1(tuple):
        if tuple == 'ready':
            print('Worker1 reports ready')
            ready1.set()

    def check_ready2(tuple):
        if tuple == 'ready':
            print('Worker2 reports ready')
            ready2.set()

    # Set up a transport called "boss"
    t = Transport('boss')

    # Listen for messages from workers
    t.subscribe('worker1', check_ready1)
    t.subscribe('worker2', check_ready2)

    # Repeat forever
    while True:

        # Set both workers as not ready.
        ready1.clear()
        ready2.clear()

        print('\nWaiting for workers to be ready')

        # Wait for both workers to have indicated that they're ready.
        # Note that the order doesn't matter. If 2 is ready first, it
        # will remain ready until 1 is also ready.

        ready1.wait()
        ready2.wait()

        print('Both workers ready. Telling them to GO!')
        t.send('worker1', 'GO!')
        t.send('worker2', 'GO!')
Example #3
0
#!/usr/bin/env python
#
# Example of coordinating two workers. The worker simply waits for
# keyboard input, and sends the message to the boss. When the boss
# sends a message, the worker just echos it. See coord_boss.py
# for a more complete explanation.

from __future__ import print_function
from six.moves import input
import six

import sys
from lcas.Transport import Transport

myname = sys.argv[1]

t = Transport(myname)
t.subscribe('boss', lambda tuple: print('Got', tuple, 'from boss'))

while True:
    t.send('boss', input())