|
369 | 369 | "\n", |
370 | 370 | "---\n", |
371 | 371 | "\n", |
372 | | - "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L84){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 372 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L87){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
373 | 373 | "\n", |
374 | 374 | "#### ThreadPoolExecutor\n", |
375 | 375 | "\n", |
|
446 | 446 | "\n", |
447 | 447 | "---\n", |
448 | 448 | "\n", |
449 | | - "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L103){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 449 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L106){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
450 | 450 | "\n", |
451 | 451 | "#### ProcessPoolExecutor\n", |
452 | 452 | "\n", |
|
580 | 580 | "name": "stdout", |
581 | 581 | "output_type": "stream", |
582 | 582 | "text": [ |
583 | | - "2026-05-13 12:03:52.455303" |
| 583 | + "2026-05-13 13:25:26.977693" |
584 | 584 | ] |
585 | 585 | }, |
586 | 586 | { |
|
608 | 608 | "name": "stdout", |
609 | 609 | "output_type": "stream", |
610 | 610 | "text": [ |
611 | | - "2026-05-13 12:03:52.557054" |
| 611 | + "2026-05-13 13:25:27.079169" |
612 | 612 | ] |
613 | 613 | }, |
614 | 614 | { |
|
636 | 636 | "name": "stdout", |
637 | 637 | "output_type": "stream", |
638 | 638 | "text": [ |
639 | | - "2026-05-13 12:03:52.657376" |
| 639 | + "2026-05-13 13:25:27.180193" |
640 | 640 | ] |
641 | 641 | }, |
642 | 642 | { |
|
664 | 664 | "name": "stdout", |
665 | 665 | "output_type": "stream", |
666 | 666 | "text": [ |
667 | | - "2026-05-13 12:03:52.759358" |
| 667 | + "2026-05-13 13:25:27.281662" |
668 | 668 | ] |
669 | 669 | }, |
670 | 670 | { |
|
692 | 692 | "name": "stdout", |
693 | 693 | "output_type": "stream", |
694 | 694 | "text": [ |
695 | | - "2026-05-13 12:03:52.861305" |
| 695 | + "2026-05-13 13:25:27.382139" |
696 | 696 | ] |
697 | 697 | }, |
698 | 698 | { |
|
778 | 778 | "name": "stdout", |
779 | 779 | "output_type": "stream", |
780 | 780 | "text": [ |
781 | | - "0 2026-05-13 12:03:53.038233 2026-05-13 12:03:53.042792 0.003980359732221225\n", |
782 | | - "3 2026-05-13 12:03:53.042931 2026-05-13 12:03:53.043358 0.0003544993380723523\n", |
783 | | - "1 2026-05-13 12:03:53.038254 2026-05-13 12:03:53.050549 0.01144644161379336\n", |
784 | | - "4 2026-05-13 12:03:53.043382 2026-05-13 12:03:53.053678 0.009921241493268762\n", |
785 | | - "2 2026-05-13 12:03:53.038261 2026-05-13 12:03:53.054528 0.01614412958800752\n", |
786 | | - "5 2026-05-13 12:03:53.050601 2026-05-13 12:03:53.071502 0.019838832903686602\n" |
| 781 | + "2 2026-05-13 13:25:27.564974 2026-05-13 13:25:27.569803 0.004192140760309271\n", |
| 782 | + "1 2026-05-13 13:25:27.564969 2026-05-13 13:25:27.569908 0.004733583519831327\n", |
| 783 | + "4 2026-05-13 13:25:27.570059 2026-05-13 13:25:27.575066 0.004417952090144302\n", |
| 784 | + "3 2026-05-13 13:25:27.570047 2026-05-13 13:25:27.577781 0.007399881148787446\n", |
| 785 | + "0 2026-05-13 13:25:27.564949 2026-05-13 13:25:27.580303 0.015048152922976935\n", |
| 786 | + "5 2026-05-13 13:25:27.575107 2026-05-13 13:25:27.580550 0.005396135128260119\n" |
787 | 787 | ] |
788 | 788 | } |
789 | 789 | ], |
|
819 | 819 | "name": "stdout", |
820 | 820 | "output_type": "stream", |
821 | 821 | "text": [ |
822 | | - "0 2026-05-13 12:03:53.094637 2026-05-13 12:03:53.103523 0.007845536618852244\n", |
823 | | - "1 2026-05-13 12:03:53.195626 2026-05-13 12:03:53.211603 0.014942779172981509\n" |
| 822 | + "0 2026-05-13 13:25:27.603860 2026-05-13 13:25:27.617834 0.012897349937030123\n", |
| 823 | + "1 2026-05-13 13:25:27.704777 2026-05-13 13:25:27.735915 0.02999927582214811\n" |
824 | 824 | ] |
825 | 825 | }, |
826 | 826 | { |
827 | 827 | "name": "stdout", |
828 | 828 | "output_type": "stream", |
829 | 829 | "text": [ |
830 | | - "2 2026-05-13 12:03:53.295724 2026-05-13 12:03:53.316481 0.020648367875254866\n", |
831 | | - "3 2026-05-13 12:03:53.395680 2026-05-13 12:03:53.418257 0.021434007873905845\n", |
832 | | - "4 2026-05-13 12:03:53.495474 2026-05-13 12:03:53.504053 0.007492717605635113\n" |
| 830 | + "2 2026-05-13 13:25:27.804897 2026-05-13 13:25:27.830147 0.024032506917510476\n", |
| 831 | + "3 2026-05-13 13:25:27.904851 2026-05-13 13:25:27.911237 0.005580292386023334\n", |
| 832 | + "4 2026-05-13 13:25:28.004162 2026-05-13 13:25:28.006516 0.001997318249937352\n" |
833 | 833 | ] |
834 | 834 | }, |
835 | 835 | { |
836 | 836 | "name": "stdout", |
837 | 837 | "output_type": "stream", |
838 | 838 | "text": [ |
839 | | - "5 2026-05-13 12:03:53.595719 2026-05-13 12:03:53.615570 0.018688364392410103\n" |
| 839 | + "5 2026-05-13 13:25:28.104945 2026-05-13 13:25:28.117438 0.011197564731975381\n" |
840 | 840 | ] |
841 | 841 | } |
842 | 842 | ], |
|
935 | 935 | "output_type": "stream", |
936 | 936 | "text": [ |
937 | 937 | "Traceback (most recent call last):\n", |
938 | | - " File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_58354/1179310912.py\", line 2, in _fail\n", |
| 938 | + " File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_62209/1179310912.py\", line 2, in _fail\n", |
939 | 939 | " async def _fail(): raise ValueError(\"this error will be printed\")\n", |
940 | 940 | " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
941 | 941 | "ValueError: this error will be printed\n" |
|
991 | 991 | "outputs": [], |
992 | 992 | "source": [ |
993 | 993 | "#| export\n", |
994 | | - "def parallel_gen(cls, items, n_workers=defaults.cpus, progress=True, **kwargs):\n", |
| 994 | + "def parallel_gen(cls, items, n_workers=defaults.cpus, progress=False, **kwargs):\n", |
995 | 995 | " \"Instantiate `cls` in `n_workers` procs & call each on a subset of `items` in parallel.\"\n", |
996 | | - " try: from fastprogress import progress_bar\n", |
997 | | - " except ImportError: return None\n", |
998 | 996 | " if not parallelable('n_workers', n_workers): n_workers = 0\n", |
999 | 997 | " if n_workers==0:\n", |
1000 | 998 | " yield from enumerate(list(cls(**kwargs)(items)))\n", |
1001 | 999 | " return\n", |
1002 | 1000 | " batches = L(chunked(items, n_chunks=n_workers))\n", |
1003 | 1001 | " idx = L(itertools.accumulate(0 + batches.map(len)))\n", |
1004 | 1002 | " queue = Queue()\n", |
1005 | | - " if progress_bar and progress: items = progress_bar(items, leave=False)\n", |
| 1003 | + " if progress:\n", |
| 1004 | + " from fastprogress import progress_bar\n", |
| 1005 | + " items = progress_bar(items, leave=False)\n", |
1006 | 1006 | " f=partial(_f_pg, cls(**kwargs), queue)\n", |
1007 | 1007 | " done=partial(_done_pg, queue, items)\n", |
1008 | 1008 | " yield from run_procs(f, done, L(batches,idx).zip())" |
|
0 commit comments