1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.4: http://docutils.sourceforge.net/" />
<title>Python processing</title>
<meta name="author" content="R Oudkerk" />
<link rel="stylesheet" href="doc/html4css1.css" type="text/css" />
</head>
<body>
<div class="document" id="python-processing">
<h1 class="title">Python processing</h1>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name" />
<col class="docinfo-content" />
<tbody valign="top">
<tr><th class="docinfo-name">Author:</th>
<td>R Oudkerk</td></tr>
<tr><th class="docinfo-name">Contact:</th>
<td>roudkerk at users.berlios.de</td></tr>
<tr class="field"><th class="docinfo-name">Url:</th><td class="field-body"><a class="reference" href="http://developer.berlios.de/projects/pyprocessing">http://developer.berlios.de/projects/pyprocessing</a></td>
</tr>
<tr><th class="docinfo-name">Version:</th>
<td>0.52</td></tr>
<tr class="field"><th class="docinfo-name">Licence:</th><td class="field-body">BSD Licence</td>
</tr>
</tbody>
</table>
<p><tt class="docutils literal"><span class="pre">processing</span></tt> is a package for the Python language which supports the
spawning of processes using the API of the standard library's
<tt class="docutils literal"><span class="pre">threading</span></tt> module. It runs on both Unix and Windows.</p>
<p>Features:</p>
<ul class="simple">
<li>Objects can be transferred between processes using pipes or
multi-producer/multi-consumer queues.</li>
<li>Objects can be shared between processes using a server process or
(for simple data) shared memory.</li>
<li>Equivalents of all the synchronization primitives in <tt class="docutils literal"><span class="pre">threading</span></tt>
are available.</li>
<li>A <tt class="docutils literal"><span class="pre">Pool</span></tt> class makes it easy to submit tasks to a pool of worker
processes.</li>
</ul>
<div class="section">
<h1><a id="links" name="links">Links</a></h1>
<ul class="simple">
<li><a class="reference" href="./doc/index.html">Documentation</a></li>
<li><a class="reference" href="./doc/INSTALL.html">Installation instructions</a></li>
<li><a class="reference" href="./doc/CHANGES.html">Changelog</a></li>
<li><a class="reference" href="./doc/THANKS.html">Acknowledgments</a></li>
<li><a class="reference" href="./doc/COPYING.html">BSD Licence</a></li>
</ul>
<p>The project is hosted at</p>
<ul class="simple">
<li><a class="reference" href="http://developer.berlios.de/projects/pyprocessing">http://developer.berlios.de/projects/pyprocessing</a></li>
</ul>
<p>The package can be downloaded from</p>
<ul class="simple">
<li><a class="reference" href="http://developer.berlios.de/project/filelist.php?group_id=9001">http://developer.berlios.de/project/filelist.php?group_id=9001</a> or</li>
<li><a class="reference" href="http://pypi.python.org/pypi/processing">http://pypi.python.org/pypi/processing</a></li>
</ul>
</div>
<div class="section">
<h1><a id="examples" name="examples">Examples</a></h1>
<p>The <tt class="docutils literal"><span class="pre">processing.Process</span></tt> class follows the API of <tt class="docutils literal"><span class="pre">threading.Thread</span></tt>.
For example</p>
<pre class="literal-block">
from processing import Process, Queue
def f(q):
q.put('hello world')
if __name__ == '__main__':
q = Queue()
p = Process(target=f, args=[q])
p.start()
print q.get()
p.join()
</pre>
<p>Synchronization primitives like locks, semaphores and conditions are
available, for example</p>
<pre class="literal-block">
>>> from processing import Condition
>>> c = Condition()
>>> print c
<Condition(<RLock(None, 0)>), 0>
>>> c.acquire()
True
>>> print c
<Condition(<RLock(MainProcess, 1)>), 0>
</pre>
<p>One can also use a manager to create shared objects either in shared
memory or in a server process, for example</p>
<pre class="literal-block">
>>> from processing import Manager
>>> manager = Manager()
>>> l = manager.list(range(10))
>>> l.reverse()
>>> print l
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
>>> print repr(l)
<Proxy[list] object at 0x00E1B3B0>
</pre>
<p>Tasks can be offloaded to a pool of worker processes in various ways,
for example</p>
<pre class="literal-block">
>>> from processing import Pool
>>> def f(x): return x*x
...
>>> p = Pool(4)
>>> result = p.mapAsync(f, range(10))
>>> print result.get(timeout=1)
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
</pre>
<a href="http://developer.berlios.de" title="BerliOS Developer">
<img src="http://developer.berlios.de/bslogo.php?group_id=9001"
width="124px" height="32px" border="0" alt="BerliOS Developer Logo"></a></div>
</div>
</body>
</html>
|