index.txt 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. # multiprocessing
  2. John Melesky
  3. (PDX Python, June 2010)
  4. ---
  5. # In the 2.6 standard library
  6. Otherwise, available from PyPI (>=2.4)
  7. ---
  8. # A note
  9. `multiprocessing` is a huge library, and deserving of a full-fledged talk (or several), rather than a module-of-the-month.
  10. The manager functionality, for example, is elaborate and useful.
  11. ---
  12. # A note
  13. `multiprocessing` is a huge library, and deserving of a full-fledged talk (or several), rather than a module-of-the-month.
  14. The manager functionality, for example, is elaborate and useful (as far as i can tell. i haven't used it. this is still just a motm talk).
  15. ---
  16. # A different note
  17. `multiprocessing` is complex, and occasionally slightly hackish. Expect the following:
  18. - These examples may not work in the REPL
  19. - Similar arguments may have different semantics depending on whether they're passed to `Process` or `Pool`
  20. - It "works" on Windows
  21. - Overall, YMMV
  22. ---
  23. # Pre-multiprocessing
  24. - fork/exec
  25. - threading
  26. ---
  27. # Pre-multiprocessing
  28. - fork/exec
  29. - threading (inspired by Java!)
  30. ---
  31. # Process
  32. [sample process code](code/proc1.py)
  33. ---
  34. # Process
  35. - name, pid, exitcode, authkey
  36. - `start()`
  37. - `run()`
  38. - `join([timeout])`
  39. - `is_alive()`
  40. - `terminate()`
  41. - daemon
  42. ---
  43. # Pool
  44. [sample pool code](code/proc2.py)
  45. ---
  46. # Pool
  47. - `apply(func[, args[, kwds]])`
  48. - `apply_async(ditto, plus callback)`
  49. - `map`, `map_async`, `imap`, `imap_unordered`
  50. - `close()`
  51. - `terminate()`
  52. - `join()`
  53. ---
  54. # Queue
  55. [(nonworking) sample queue code](code/proc3.py)
  56. ---
  57. # Queue
  58. See Queue.Queue
  59. - `empty()`, `full()`, `qsize()`
  60. - `put(item[, block[, timeout]])`
  61. - `put_nowait(item)`
  62. - `get([block[, timeout]])`
  63. - `get_nowait()`
  64. ---
  65. # Pipe
  66. [(semiworking) sample pipe code](code/proc4.py)
  67. ---
  68. # Connection
  69. - `send(obj)`
  70. - `recv()`
  71. - `fileno()`
  72. - `close()`
  73. - `poll([timeout])`
  74. - `send_bytes`, `recv_bytes`, `recv_bytes_into`
  75. ---
  76. # Stuff i'm not covering
  77. - `Lock`
  78. - shared memory maps (`Value`, `Array`)
  79. - `Manager`s, both local and remote
  80. - Proxies
  81. - `Namespace`
  82. - `Listener` and `Client`
  83. - lots of other stuff
  84. ---
  85. # Final example
  86. A [web scraper](code/scraper.py) with Process and Queue
  87. ---