Skip to content

Instantly share code, notes, and snippets.

@MarkLavrynenko
Created June 27, 2015 17:42
Show Gist options
  • Save MarkLavrynenko/02711dc9c16242afd96f to your computer and use it in GitHub Desktop.
Save MarkLavrynenko/02711dc9c16242afd96f to your computer and use it in GitHub Desktop.

Revisions

  1. MarkLavrynenko created this gist Jun 27, 2015.
    25 changes: 25 additions & 0 deletions gistfile1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    from multiprocessing import Pool, Pipe, Process

    def work(process_name, pipe):
    while True:
    print("%s Start w8!" % process_name)
    data = pipe.recv()
    print("%s You sent %s" % (process_name, data))


    if __name__ == "__main__":
    parent, child = Pipe()
    p1 = Process(target=work, args=("P1", child,))
    p1.start()

    p2 = Process(target=work, args=("P2", child,))
    p2.start()
    while True:
    try:
    data = raw_input()
    parent.send(data)
    except KeyboardInterrupt:
    print("On KeyboardInterrupt")
    child.close()
    parent.close()
    exit(0)