index.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <html> <head>
  2. <title>multiprocessing as the module of the month</title>
  3. <style>
  4. body {
  5. background-color: #cfdada;
  6. }
  7. .slide {
  8. font-family: Gill Sans;
  9. border: 2px solid #778888;
  10. background-color: #e7fafa;;
  11. padding: 2%;
  12. width: 94%;
  13. }
  14. h1 {
  15. text-align: center;
  16. }
  17. pre {
  18. border: 1px solid #446666;
  19. background-color: #e8ffff;
  20. padding: 2px;
  21. }
  22. </style>
  23. <script src="scripts/jquery-1.2.3.js" type="text/javascript"></script>
  24. <script src="scripts/slideshow.js" type="text/javascript"></script>
  25. </head>
  26. <body>
  27. <div class='slide'>
  28. <h1>multiprocessing</h1>
  29. <p>John Melesky
  30. (PDX Python, June 2010)</p>
  31. </div>
  32. <div class='slide'>
  33. <h1>In the 2.6 standard library</h1>
  34. <p>Otherwise, available from PyPI (&gt;=2.4)</p>
  35. </div>
  36. <div class='slide'>
  37. <h1>A note</h1>
  38. <p><code>multiprocessing</code> is a huge library, and deserving of a full-fledged talk (or several), rather than a module-of-the-month.</p>
  39. <p>The manager functionality, for example, is elaborate and useful.</p>
  40. </div>
  41. <div class='slide'>
  42. <h1>A note</h1>
  43. <p><code>multiprocessing</code> is a huge library, and deserving of a full-fledged talk (or several), rather than a module-of-the-month.</p>
  44. <p>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).</p>
  45. </div>
  46. <div class='slide'>
  47. <h1>A different note</h1>
  48. <p><code>multiprocessing</code> is complex, and occasionally slightly hackish. Expect the following:</p>
  49. <ul>
  50. <li>These examples may not work in the REPL</li>
  51. <li>Similar arguments may have different semantics depending on whether they're passed to <code>Process</code> or <code>Pool</code></li>
  52. <li>It "works" on Windows</li>
  53. <li>Overall, YMMV</li>
  54. </ul>
  55. </div>
  56. <div class='slide'>
  57. <h1>Pre-multiprocessing</h1>
  58. <ul>
  59. <li>fork/exec</li>
  60. <li>threading</li>
  61. </ul>
  62. </div>
  63. <div class='slide'>
  64. <h1>Pre-multiprocessing</h1>
  65. <ul>
  66. <li>fork/exec</li>
  67. <li>threading (inspired by Java!)</li>
  68. </ul>
  69. </div>
  70. <div class='slide'>
  71. <h1>Process</h1>
  72. <p><a href="code/proc1.py">sample process code</a></p>
  73. </div>
  74. <div class='slide'>
  75. <h1>Process</h1>
  76. <ul>
  77. <li>name, pid, exitcode, authkey</li>
  78. <li><code>start()</code></li>
  79. <li><code>run()</code></li>
  80. <li><code>join([timeout])</code></li>
  81. <li><code>is_alive()</code></li>
  82. <li><code>terminate()</code></li>
  83. <li>daemon</li>
  84. </ul>
  85. </div>
  86. <div class='slide'>
  87. <h1>Pool</h1>
  88. <p><a href="code/proc2.py">sample pool code</a></p>
  89. </div>
  90. <div class='slide'>
  91. <h1>Pool</h1>
  92. <ul>
  93. <li><code>apply(func[, args[, kwds]])</code></li>
  94. <li><code>apply_async(ditto, plus callback)</code></li>
  95. <li><code>map</code>, <code>map_async</code>, <code>imap</code>, <code>imap_unordered</code></li>
  96. <li><code>close()</code></li>
  97. <li><code>terminate()</code></li>
  98. <li><code>join()</code></li>
  99. </ul>
  100. </div>
  101. <div class='slide'>
  102. <h1>Queue</h1>
  103. <p><a href="code/proc3.py">(nonworking) sample queue code</a></p>
  104. </div>
  105. <div class='slide'>
  106. <h1>Queue</h1>
  107. <p>See Queue.Queue</p>
  108. <ul>
  109. <li><code>empty()</code>, <code>full()</code>, <code>qsize()</code></li>
  110. <li><code>put(item[, block[, timeout]])</code></li>
  111. <li><code>put_nowait(item)</code></li>
  112. <li><code>get([block[, timeout]])</code></li>
  113. <li><code>get_nowait()</code></li>
  114. </ul>
  115. </div>
  116. <div class='slide'>
  117. <h1>Pipe</h1>
  118. <p><a href="code/proc4.py">(semiworking) sample pipe code</a></p>
  119. </div>
  120. <div class='slide'>
  121. <h1>Connection</h1>
  122. <ul>
  123. <li><code>send(obj)</code></li>
  124. <li><code>recv()</code></li>
  125. <li><code>fileno()</code></li>
  126. <li><code>close()</code></li>
  127. <li><code>poll([timeout])</code></li>
  128. <li><code>send_bytes</code>, <code>recv_bytes</code>, <code>recv_bytes_into</code></li>
  129. </ul>
  130. </div>
  131. <div class='slide'>
  132. <h1>Stuff i'm not covering</h1>
  133. <ul>
  134. <li><code>Lock</code></li>
  135. <li>shared memory maps (<code>Value</code>, <code>Array</code>)</li>
  136. <li><code>Manager</code>s, both local and remote</li>
  137. <li>Proxies</li>
  138. <li><code>Namespace</code></li>
  139. <li><code>Listener</code> and <code>Client</code></li>
  140. <li>lots of other stuff</li>
  141. </ul>
  142. </div>
  143. <div class='slide'>
  144. <h1>Final example</h1>
  145. <p>A <a href="code/scraper.py">web scraper</a> with Process and Queue</p>
  146. </div>
  147. <div class='slide'>
  148. <p></p>
  149. </div>
  150. </body></html>