|
215 | 215 | "Same as Python's ThreadPoolExecutor, except can pass `max_workers==0` for serial execution" |
216 | 216 | ], |
217 | 217 | "text/plain": [ |
218 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x1034390a0>" |
| 218 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
219 | 219 | ] |
220 | 220 | }, |
221 | 221 | "execution_count": null, |
|
276 | 276 | "Same as Python's ProcessPoolExecutor, except can pass `max_workers==0` for serial execution" |
277 | 277 | ], |
278 | 278 | "text/plain": [ |
279 | | - "<nbdev.showdoc.BasicMarkdownRenderer at 0x10f325e20>" |
| 279 | + "<nbdev.showdoc.BasicMarkdownRenderer>" |
280 | 280 | ] |
281 | 281 | }, |
282 | 282 | "execution_count": null, |
|
312 | 312 | " kwpool = {}\n", |
313 | 313 | " if threadpool: pool = ThreadPoolExecutor\n", |
314 | 314 | " else:\n", |
315 | | - " if not method and sys.platform == 'darwin': method='fork'\n", |
| 315 | + " if not method and sys.platform == 'darwin' and not IN_NOTEBOOK: method='spawn'\n", |
316 | 316 | " if method: kwpool['mp_context'] = get_context(method)\n", |
317 | 317 | " pool = ProcessPoolExecutor\n", |
318 | 318 | " with pool(n_workers, pause=pause, **kwpool) as ex:\n", |
|
345 | 345 | "source": [ |
346 | 346 | "inp,exp = range(50),range(1,51)\n", |
347 | 347 | "\n", |
348 | | - "# test_eq(parallel(add_one, inp, method='spawn', n_workers=2, progress=False), exp)\n", |
349 | 348 | "test_eq(parallel(add_one, inp, n_workers=2, progress=False), exp)\n", |
350 | 349 | "test_eq(parallel(add_one, inp, threadpool=True, n_workers=2, progress=False), exp)\n", |
351 | 350 | "test_eq(parallel(add_one, inp, n_workers=1, a=2), range(2,52))\n", |
|
369 | 368 | "name": "stdout", |
370 | 369 | "output_type": "stream", |
371 | 370 | "text": [ |
372 | | - "0 2022-07-26 04:12:18.858918\n", |
373 | | - "1 2022-07-26 04:12:19.110316\n", |
374 | | - "2 2022-07-26 04:12:19.362060\n", |
375 | | - "3 2022-07-26 04:12:19.612606\n", |
376 | | - "4 2022-07-26 04:12:19.863821\n" |
| 371 | + "0 2022-08-07 05:10:05.999916\n", |
| 372 | + "1 2022-08-07 05:10:06.252031\n", |
| 373 | + "2 2022-08-07 05:10:06.503603\n", |
| 374 | + "3 2022-08-07 05:10:06.755216\n", |
| 375 | + "4 2022-08-07 05:10:07.006702\n" |
377 | 376 | ] |
378 | 377 | } |
379 | 378 | ], |
|
387 | 386 | "parallel(print_time, range(5), n_workers=2, pause=0.25);" |
388 | 387 | ] |
389 | 388 | }, |
390 | | - { |
391 | | - "cell_type": "code", |
392 | | - "execution_count": null, |
393 | | - "metadata": {}, |
394 | | - "outputs": [], |
395 | | - "source": [ |
396 | | - "def die_sometimes(x):\n", |
397 | | - "# if 3<x<6: raise Exception(f\"exc: {x}\")\n", |
398 | | - " return x*2" |
399 | | - ] |
400 | | - }, |
401 | 389 | { |
402 | 390 | "cell_type": "code", |
403 | 391 | "execution_count": null, |
|
415 | 403 | } |
416 | 404 | ], |
417 | 405 | "source": [ |
| 406 | + "#|hide\n", |
| 407 | + "def die_sometimes(x):\n", |
| 408 | + "# if 3<x<6: raise Exception(f\"exc: {x}\")\n", |
| 409 | + " return x*2\n", |
| 410 | + "\n", |
418 | 411 | "parallel(die_sometimes, range(8))" |
419 | 412 | ] |
420 | 413 | }, |
|
582 | 575 | "outputs": [], |
583 | 576 | "source": [ |
584 | 577 | "#|hide\n", |
585 | | - "#|eval: false\n", |
586 | 578 | "from nbdev import nbdev_export\n", |
587 | 579 | "nbdev_export()" |
588 | 580 | ] |
|
0 commit comments