README.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. .. default-role:: literal
  2. .. include:: doc/version.txt
  3. ===================
  4. Python processing
  5. ===================
  6. :Author: R Oudkerk
  7. :Contact: roudkerk at users.berlios.de
  8. :Url: http://developer.berlios.de/projects/pyprocessing
  9. :Version: |version|
  10. :Licence: BSD Licence
  11. `processing` is a package for the Python language which supports the
  12. spawning of processes using the API of the standard library's
  13. `threading` module. It runs on both Unix and Windows.
  14. Features:
  15. * Objects can be transferred between processes using pipes or
  16. multi-producer/multi-consumer queues.
  17. * Objects can be shared between processes using a server process or
  18. (for simple data) shared memory.
  19. * Equivalents of all the synchronization primitives in `threading`
  20. are available.
  21. * A `Pool` class makes it easy to submit tasks to a pool of worker
  22. processes.
  23. Links
  24. =====
  25. * `Documentation <./doc/index.html>`_
  26. * `Installation instructions <./doc/INSTALL.html>`_
  27. * `Changelog <./doc/CHANGES.html>`_
  28. * `Acknowledgments <./doc/THANKS.html>`_
  29. * `BSD Licence <./doc/COPYING.html>`_
  30. The project is hosted at
  31. * http://developer.berlios.de/projects/pyprocessing
  32. The package can be downloaded from
  33. * http://developer.berlios.de/project/filelist.php?group_id=9001 or
  34. * http://pypi.python.org/pypi/processing
  35. Examples
  36. ========
  37. The `processing.Process` class follows the API of `threading.Thread`.
  38. For example ::
  39. from processing import Process, Queue
  40. def f(q):
  41. q.put('hello world')
  42. if __name__ == '__main__':
  43. q = Queue()
  44. p = Process(target=f, args=[q])
  45. p.start()
  46. print q.get()
  47. p.join()
  48. Synchronization primitives like locks, semaphores and conditions are
  49. available, for example ::
  50. >>> from processing import Condition
  51. >>> c = Condition()
  52. >>> print c
  53. <Condition(<RLock(None, 0)>), 0>
  54. >>> c.acquire()
  55. True
  56. >>> print c
  57. <Condition(<RLock(MainProcess, 1)>), 0>
  58. One can also use a manager to create shared objects either in shared
  59. memory or in a server process, for example ::
  60. >>> from processing import Manager
  61. >>> manager = Manager()
  62. >>> l = manager.list(range(10))
  63. >>> l.reverse()
  64. >>> print l
  65. [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
  66. >>> print repr(l)
  67. <Proxy[list] object at 0x00E1B3B0>
  68. Tasks can be offloaded to a pool of worker processes in various ways,
  69. for example ::
  70. >>> from processing import Pool
  71. >>> def f(x): return x*x
  72. ...
  73. >>> p = Pool(4)
  74. >>> result = p.mapAsync(f, range(10))
  75. >>> print result.get(timeout=1)
  76. [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
  77. .. raw:: html
  78. <a href="http://developer.berlios.de" title="BerliOS Developer">
  79. <img src="http://developer.berlios.de/bslogo.php?group_id=9001"
  80. width="124px" height="32px" border="0" alt="BerliOS Developer Logo"></a>