Ejemplo n.º 1
0
from cloudbutton.multiprocessing import Process, Pipe


def f(conn):
    conn.send([42, None, 'hello'])
    conn.close()


if __name__ == '__main__':
    parent_conn, child_conn = Pipe()
    p = Process(target=f, args=(child_conn, ))
    p.start()
    print(parent_conn.recv())  # prints "[42, None, 'hello']"
    p.join()
Ejemplo n.º 2
0
def worker(q):
    working = True
    while working:
        x = q.get()

        # Do work that may fail
        assert x < 10

        # Confirm task
        q.task_done()

        if x == -1:
            working = False


if __name__ == '__main__':
    q = JoinableQueue()
    p = Process(target=worker, args=(q, ))
    p.start()

    for x in range(10):
        q.put(x)

    # uncomment to hang on the q.join
    #q.put(11)
    q.join()

    q.put(-1)  # end loop
    p.join()
Ejemplo n.º 3
0
from cloudbutton.multiprocessing import Process, SimpleQueue


def f(q):
    q.put([42, None, 'hello World'])


if __name__ == '__main__':
    q = SimpleQueue()
    p = Process(target=f, args=(q,))
    p.start()
    print(q.get())    # prints "[42, None, 'hello']"
    p.join()
Ejemplo n.º 4
0
from cloudbutton.multiprocessing import Process


def f(name):
    print('hello', name)


if __name__ == '__main__':
    p = Process(target=f, args=('bob', ))
    p.start()
    p.join()