1.1 --- a/examples/PyGmy/ppygmy.py Sun Jan 14 19:11:03 2007 +0000
1.2 +++ b/examples/PyGmy/ppygmy.py Sun Jan 14 21:56:31 2007 +0000
1.3 @@ -365,36 +365,34 @@
1.4 """
1.5
1.6 image = Image.new("RGB", (self.width,self.height))
1.7 - draw = ImageDraw.Draw(image)
1.8 - total = self.width*self.height
1.9 - count = 0
1.10 - nproc = 0
1.11 -
1.12 - exchange = pprocess.Exchange()
1.13 - y = 0
1.14 - nproc = len(exchange.active())
1.15 -
1.16 - while y < self.height or nproc > 0:
1.17 - if y < self.height and nproc < limit:
1.18 - channel = pprocess.start(self.render_row, y)
1.19 - exchange.add(channel)
1.20 - y += 1
1.21 + exchange = PyGmyExchange(limit=limit)
1.22 + exchange.draw = ImageDraw.Draw(image)
1.23 + exchange.total = self.width*self.height
1.24 + exchange.count = 0
1.25
1.26 - for channel in exchange.ready():
1.27 - sy, row = channel.receive()
1.28 - sx = 0
1.29 - for col in row:
1.30 - draw.point((sx,sy),fill=(col.x*255,col.y*255,col.z*255))
1.31 - #depth=depth/self.backplane
1.32 - #draw.point((sx,sy),fill=(depth*255,depth*255,depth*255))
1.33 - count=count+1
1.34 - sx += 1
1.35 + for y in range(0, self.height):
1.36 + channel = pprocess.start(self.render_row, y)
1.37 + exchange.add_wait(channel)
1.38
1.39 - percentstr = str(int((count/float(total))*100))+"%"
1.40 - print "\b\b\b"+percentstr
1.41 -
1.42 - nproc = len(exchange.active())
1.43 -
1.44 + exchange.finish()
1.45 image.save(filename)
1.46
1.47 +class PyGmyExchange(pprocess.Exchange):
1.48 +
1.49 + "A convenience class for parallelisation."
1.50 +
1.51 + def store_data(self, channel):
1.52 +
1.53 + "Store the data arriving on the given 'channel'."
1.54 +
1.55 + sy, row = channel.receive()
1.56 + sx = 0
1.57 + for col in row:
1.58 + self.draw.point((sx,sy),fill=(col.x*255,col.y*255,col.z*255))
1.59 + self.count = self.count + 1
1.60 + sx += 1
1.61 +
1.62 + percentstr = str(int((self.count/float(self.total))*100))+"%"
1.63 + print "\b\b\b"+percentstr
1.64 +
1.65 # vim: tabstop=4 expandtab shiftwidth=4