2016-12-19 | Paul Boddie | file changeset files shortlog | Added support for counting CPU cores on Mac OS X. |
paulb@75 | 1 | #!/usr/bin/env python |
paulb@75 | 2 | |
paulb@75 | 3 | import pprocess |
paulb@75 | 4 | |
paulb@75 | 5 | class Ex(pprocess.Exchange): |
paulb@75 | 6 | def store_data(self, channel): |
paulb@75 | 7 | data = channel.receive() |
paulb@75 | 8 | print "Parent:", data |
paulb@75 | 9 | channel.send(data - 1) |
paulb@75 | 10 | print "Parent sent" |
paulb@75 | 11 | |
paulb@75 | 12 | def child(channel, data): |
paulb@75 | 13 | while data != 0: |
paulb@75 | 14 | print "Child:", data |
paulb@75 | 15 | channel.send(data) |
paulb@75 | 16 | print "Child sent" |
paulb@75 | 17 | data = channel.receive() |
paulb@75 | 18 | |
paulb@75 | 19 | ex = Ex() |
paulb@75 | 20 | ex.add(pprocess.start(child, 20)) |
paulb@75 | 21 | ex.finish() |
paulb@75 | 22 | |
paulb@75 | 23 | # vim: tabstop=4 expandtab shiftwidth=4 |