1.1 --- a/README.txt Sun Jan 05 00:56:40 2014 +0100
1.2 +++ b/README.txt Wed Aug 19 11:31:24 2015 +0200
1.3 @@ -7,6 +7,12 @@
1.4 systems with multiple CPUs or multicore CPUs, processes should take advantage
1.5 of as many CPUs or cores as the operating system permits.
1.6
1.7 +Since pprocess distributes work to other processes, certain aspects of the
1.8 +behaviour of those processes may differ from the normal behaviour of such
1.9 +code. For example, any mutable objects distributed to other processes can
1.10 +still be modified, but any modifications will not be visible outside the
1.11 +processes making such modifications. The
1.12 +
1.13 Tutorial
1.14 --------
1.15
1.16 @@ -123,6 +129,22 @@
1.17 PYTHONPATH=. python examples/concurrency-sig/bottles.py
1.18 PYTHONPATH=. python examples/concurrency-sig/bottles_heartbeat.py
1.19
1.20 +Examples of Modifying Mutable Objects
1.21 +-------------------------------------
1.22 +
1.23 +Mutable objects can be modified in processes created by pprocess, but the
1.24 +modifications will not be visible in the parent process. The following
1.25 +examples illustrate the problem:
1.26 +
1.27 +PYTHONPATH=. python examples/simple_mutable.py
1.28 +PYTHONPATH=. python examples/simple_mutable_queue.py
1.29 +
1.30 +The former, non-parallel program will display the expected result of the
1.31 +computation, whereas the latter, parallel program will fail to do so. This is
1.32 +because the latter attempts to modify the input collection in order to use it
1.33 +as a result collection, but these modifications are not propagated back to the
1.34 +parent process.
1.35 +
1.36 Test Programs
1.37 -------------
1.38
1.39 @@ -167,6 +189,12 @@
1.40 available only on "UNIX"; it has only been tested repeatedly on a GNU/Linux
1.41 system, and occasionally on systems running OpenSolaris.
1.42
1.43 +New in pprocess 0.5.2 (Changes since pprocess 0.5.1)
1.44 +----------------------------------------------------
1.45 +
1.46 + * Added examples involving mutable objects and the inability of pprocess to
1.47 + automatically propagate changes to such objects back to parent processes.
1.48 +
1.49 New in pprocess 0.5.1 (Changes since pprocess 0.5)
1.50 --------------------------------------------------
1.51
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/simple_mutation.py Wed Aug 19 11:31:24 2015 +0200
2.3 @@ -0,0 +1,54 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"""
2.7 +A simple example of sequential computation using a function, attempting to
2.8 +modify a list/array.
2.9 +"""
2.10 +
2.11 +import time
2.12 +#import random
2.13 +
2.14 +# Array size.
2.15 +
2.16 +N = 10
2.17 +delay = 1
2.18 +
2.19 +# Work function.
2.20 +
2.21 +def calculate(results, i, j):
2.22 +
2.23 + """
2.24 + A supposedly time-consuming calculation on 'results' using 'i' and 'j'.
2.25 + """
2.26 +
2.27 + #time.sleep(delay * random.random())
2.28 + time.sleep(delay)
2.29 + results[i * N + j] *= 2
2.30 +
2.31 +# Main program.
2.32 +
2.33 +if __name__ == "__main__":
2.34 +
2.35 + t = time.time()
2.36 +
2.37 + # Initialise an array.
2.38 +
2.39 + results = range(0, 100)
2.40 +
2.41 + # Perform the work.
2.42 +
2.43 + print "Calculating..."
2.44 + for i in range(0, N):
2.45 + for j in range(0, N):
2.46 + calculate(results, i, j)
2.47 +
2.48 + # Show the results.
2.49 +
2.50 + for i in range(0, N):
2.51 + for result in results[i*N:i*N+N]:
2.52 + print result,
2.53 + print
2.54 +
2.55 + print "Time taken:", time.time() - t
2.56 +
2.57 +# vim: tabstop=4 expandtab shiftwidth=4
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/examples/simple_mutation_queue.py Wed Aug 19 11:31:24 2015 +0200
3.3 @@ -0,0 +1,59 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +"""
3.7 +A simple example of sequential computation using a function, attempting to
3.8 +modify a list/array.
3.9 +"""
3.10 +
3.11 +import pprocess
3.12 +import time
3.13 +#import random
3.14 +
3.15 +# Array size.
3.16 +
3.17 +N = 10
3.18 +limit = 10
3.19 +delay = 1
3.20 +
3.21 +# Work function.
3.22 +
3.23 +def calculate(results, i, j):
3.24 +
3.25 + """
3.26 + A supposedly time-consuming calculation on 'results' using 'i' and 'j'.
3.27 + """
3.28 +
3.29 + #time.sleep(delay * random.random())
3.30 + time.sleep(delay)
3.31 + results[i * N + j] *= 2
3.32 +
3.33 +# Main program.
3.34 +
3.35 +if __name__ == "__main__":
3.36 +
3.37 + t = time.time()
3.38 +
3.39 + queue = pprocess.Queue(limit=limit)
3.40 + calc = queue.manage(pprocess.MakeParallel(calculate))
3.41 +
3.42 + # Initialise an array.
3.43 +
3.44 + results = range(0, 100)
3.45 +
3.46 + # Perform the work.
3.47 +
3.48 + print "Calculating..."
3.49 + for i in range(0, N):
3.50 + for j in range(0, N):
3.51 + calc(results, i, j)
3.52 +
3.53 + # Show the results.
3.54 +
3.55 + for i in range(0, N):
3.56 + for result in results[i*N:i*N+N]:
3.57 + print result,
3.58 + print
3.59 +
3.60 + print "Time taken:", time.time() - t
3.61 +
3.62 +# vim: tabstop=4 expandtab shiftwidth=4