pprocess

Changeset

75:4c74a30f60f8
2007-03-28 paulb raw files shortlog changelog graph [project @ 2007-03-28 23:52:25 by paulb] Added a test of two-way communication. rel-0-2-4
tests/two_way.py (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tests/two_way.py	Wed Mar 28 23:52:25 2007 +0000
     1.3 @@ -0,0 +1,23 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +import pprocess
     1.7 +
     1.8 +class Ex(pprocess.Exchange):
     1.9 +    def store_data(self, channel):
    1.10 +        data = channel.receive()
    1.11 +        print "Parent:", data
    1.12 +        channel.send(data - 1)
    1.13 +        print "Parent sent"
    1.14 +
    1.15 +def child(channel, data):
    1.16 +    while data != 0:
    1.17 +        print "Child:", data
    1.18 +        channel.send(data)
    1.19 +        print "Child sent"
    1.20 +        data = channel.receive()
    1.21 +
    1.22 +ex = Ex()
    1.23 +ex.add(pprocess.start(child, 20))
    1.24 +ex.finish()
    1.25 +
    1.26 +# vim: tabstop=4 expandtab shiftwidth=4