|
70 | 70 | "cell_type": "code", |
71 | 71 | "execution_count": null, |
72 | 72 | "metadata": {}, |
73 | | - "outputs": [], |
| 73 | + "outputs": [ |
| 74 | + { |
| 75 | + "name": "stdout", |
| 76 | + "output_type": "stream", |
| 77 | + "text": [ |
| 78 | + "first\n", |
| 79 | + "second\n" |
| 80 | + ] |
| 81 | + } |
| 82 | + ], |
74 | 83 | "source": [ |
75 | 84 | "@threaded\n", |
76 | 85 | "def _1():\n", |
|
83 | 92 | " print(\"first\")\n", |
84 | 93 | "\n", |
85 | 94 | "_1()\n", |
86 | | - "_2();" |
| 95 | + "_2()\n", |
| 96 | + "time.sleep(0.1)" |
87 | 97 | ] |
88 | 98 | }, |
89 | 99 | { |
|
107 | 117 | "name": "stdout", |
108 | 118 | "output_type": "stream", |
109 | 119 | "text": [ |
110 | | - "first\n" |
| 120 | + "first\n", |
| 121 | + "second\n" |
111 | 122 | ] |
112 | 123 | } |
113 | 124 | ], |
|
120 | 131 | "@startthread\n", |
121 | 132 | "def _():\n", |
122 | 133 | " time.sleep(0.01)\n", |
123 | | - " print(\"first\")" |
| 134 | + " print(\"first\")\n", |
| 135 | + "\n", |
| 136 | + "time.sleep(0.1)" |
124 | 137 | ] |
125 | 138 | }, |
126 | 139 | { |
|
155 | 168 | "cell_type": "code", |
156 | 169 | "execution_count": null, |
157 | 170 | "metadata": {}, |
158 | | - "outputs": [ |
159 | | - { |
160 | | - "name": "stdout", |
161 | | - "output_type": "stream", |
162 | | - "text": [ |
163 | | - "first\n" |
164 | | - ] |
165 | | - } |
166 | | - ], |
| 171 | + "outputs": [], |
167 | 172 | "source": [ |
168 | 173 | "#export\n", |
169 | 174 | "def _call(lock, pause, n, g, item):\n", |
|
184 | 189 | "outputs": [], |
185 | 190 | "source": [ |
186 | 191 | "#export\n", |
187 | | - "class ProcessPoolExecutor(concurrent.futures.ProcessPoolExecutor):\n", |
188 | | - " \"Same as Python's ProcessPoolExecutor, except can pass `max_workers==0` for serial execution\"\n", |
| 192 | + "class ThreadPoolExecutor(concurrent.futures.ThreadPoolExecutor):\n", |
| 193 | + " \"Same as Python's ThreadPoolExecutor, except can pass `max_workers==0` for serial execution\"\n", |
189 | 194 | " def __init__(self, max_workers=defaults.cpus, on_exc=print, pause=0, **kwargs):\n", |
190 | 195 | " if max_workers is None: max_workers=defaults.cpus\n", |
191 | 196 | " store_attr()\n", |
|
202 | 207 | " except Exception as e: self.on_exc(e)" |
203 | 208 | ] |
204 | 209 | }, |
| 210 | + { |
| 211 | + "cell_type": "code", |
| 212 | + "execution_count": null, |
| 213 | + "metadata": {}, |
| 214 | + "outputs": [ |
| 215 | + { |
| 216 | + "data": { |
| 217 | + "text/markdown": [ |
| 218 | + "<h4 id=\"ThreadPoolExecutor\" class=\"doc_header\"><code>class</code> <code>ThreadPoolExecutor</code><a href=\"\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n", |
| 219 | + "\n", |
| 220 | + "> <code>ThreadPoolExecutor</code>(**`max_workers`**=*`64`*, **`on_exc`**=*`print`*, **`pause`**=*`0`*, **\\*\\*`kwargs`**) :: [`ThreadPoolExecutor`](/parallel.html#ThreadPoolExecutor)\n", |
| 221 | + "\n", |
| 222 | + "Same as Python's ThreadPoolExecutor, except can pass `max_workers==0` for serial execution" |
| 223 | + ], |
| 224 | + "text/plain": [ |
| 225 | + "<IPython.core.display.Markdown object>" |
| 226 | + ] |
| 227 | + }, |
| 228 | + "metadata": {}, |
| 229 | + "output_type": "display_data" |
| 230 | + } |
| 231 | + ], |
| 232 | + "source": [ |
| 233 | + "show_doc(ThreadPoolExecutor, title_level=4)" |
| 234 | + ] |
| 235 | + }, |
205 | 236 | { |
206 | 237 | "cell_type": "code", |
207 | 238 | "execution_count": null, |
208 | 239 | "metadata": {}, |
209 | 240 | "outputs": [], |
210 | 241 | "source": [ |
211 | 242 | "#export\n", |
212 | | - "class ThreadPoolExecutor(concurrent.futures.ThreadPoolExecutor):\n", |
213 | | - " \"Same as Python's ThreadPoolExecutor, except can pass `max_workers==0` for serial execution\"\n", |
| 243 | + "class ProcessPoolExecutor(concurrent.futures.ProcessPoolExecutor):\n", |
| 244 | + " \"Same as Python's ProcessPoolExecutor, except can pass `max_workers==0` for serial execution\"\n", |
214 | 245 | " def __init__(self, max_workers=defaults.cpus, on_exc=print, pause=0, **kwargs):\n", |
215 | 246 | " if max_workers is None: max_workers=defaults.cpus\n", |
216 | 247 | " store_attr()\n", |
|
368 | 399 | "name": "stdout", |
369 | 400 | "output_type": "stream", |
370 | 401 | "text": [ |
371 | | - "0 2020-12-11 18:28:04.960255\n", |
372 | | - "1 2020-12-11 18:28:05.211221\n", |
373 | | - "2 2020-12-11 18:28:05.461427\n", |
374 | | - "3 2020-12-11 18:28:05.711582\n", |
375 | | - "4 2020-12-11 18:28:05.962502\n" |
| 402 | + "1 2020-12-11 19:32:27.930895\n", |
| 403 | + "0 2020-12-11 19:32:28.181040\n", |
| 404 | + "2 2020-12-11 19:32:28.431867\n", |
| 405 | + "3 2020-12-11 19:32:28.682935\n", |
| 406 | + "4 2020-12-11 19:32:28.933846\n" |
376 | 407 | ] |
377 | 408 | } |
378 | 409 | ], |
|
0 commit comments