index.html 5.0 KB

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