# HG changeset patch # User paulb # Date 1184541023 0 # Node ID 695f2a2a776ca915ea69e6bf61a824dea3ca521f # Parent 93872f29ad5147ca6ac77131056f880f13ead03e [project @ 2007-07-15 23:10:23 by paulb] Introduced managed callables and made the exchange handle more of the housekeeping internally. diff -r 93872f29ad51 -r 695f2a2a776c examples/PyGmy/ppygmy.py --- a/examples/PyGmy/ppygmy.py Sun Jul 15 23:09:29 2007 +0000 +++ b/examples/PyGmy/ppygmy.py Sun Jul 15 23:10:23 2007 +0000 @@ -365,14 +365,12 @@ given process 'limit' to constrain the number of processes used. """ - image = Image.new("RGB", (self.width,self.height)) - exchange = PyGmyExchange(limit=limit) - exchange.draw = ImageDraw.Draw(image) - exchange.total = self.width*self.height - exchange.count = 0 + image = Image.new("RGB", (self.width, self.height)) + exchange = PyGmyExchange(self.width, self.height, image, limit=limit) + render_row = exchange.manage(self.render_row) for y in range(0, self.height): - exchange.start(self.render_row, y) + render_row(y) exchange.finish() image.save(filename) @@ -381,6 +379,18 @@ "A convenience class for parallelisation." + def __init__(self, width, height, image, *args, **kw): + + """ + Initialise the exchange, adding extra PyGmy-specific data such as the + 'width' and 'height' of the eventual 'image'. + """ + + pprocess.Exchange.__init__(self, *args, **kw) + self.draw = ImageDraw.Draw(image) + self.total = width * height + self.count = 0 + def store_data(self, channel): "Store the data arriving on the given 'channel'."