|
179 | 179 | "outputs": [], |
180 | 180 | "source": [ |
181 | 181 | "#| export\n", |
182 | | - "def startthread(f):\n", |
| 182 | + "def startthread(f=None, daemon=False):\n", |
183 | 183 | " \"Like `threaded`, but start thread immediately\"\n", |
184 | | - " return threaded(f)()" |
| 184 | + " def _f(f): return threaded(daemon=daemon)(f)()\n", |
| 185 | + " return _f(f) if f else _f\n" |
185 | 186 | ] |
186 | 187 | }, |
187 | 188 | { |
|
194 | 195 | "name": "stdout", |
195 | 196 | "output_type": "stream", |
196 | 197 | "text": [ |
197 | | - "first\n" |
198 | | - ] |
199 | | - }, |
200 | | - { |
201 | | - "name": "stdout", |
202 | | - "output_type": "stream", |
203 | | - "text": [ |
| 198 | + "first\n", |
204 | 199 | "second\n" |
205 | 200 | ] |
206 | 201 | } |
|
219 | 214 | "time.sleep(0.1)" |
220 | 215 | ] |
221 | 216 | }, |
| 217 | + { |
| 218 | + "cell_type": "code", |
| 219 | + "execution_count": null, |
| 220 | + "id": "c60e7d47", |
| 221 | + "metadata": {}, |
| 222 | + "outputs": [], |
| 223 | + "source": [ |
| 224 | + "@startthread(daemon=True)\n", |
| 225 | + "def f(): time.sleep(0.01)\n", |
| 226 | + "\n", |
| 227 | + "assert f.daemon" |
| 228 | + ] |
| 229 | + }, |
222 | 230 | { |
223 | 231 | "cell_type": "code", |
224 | 232 | "execution_count": null, |
|
227 | 235 | "outputs": [], |
228 | 236 | "source": [ |
229 | 237 | "#| export\n", |
230 | | - "def startproc(f):\n", |
| 238 | + "def startproc(f=None, daemon=False):\n", |
231 | 239 | " \"Like `threaded(True)`, but start Process immediately\"\n", |
232 | | - " return threaded(True)(f)()" |
| 240 | + " def _f(f): return threaded(True, daemon=daemon)(f)()\n", |
| 241 | + " return _f(f) if f else _f\n" |
233 | 242 | ] |
234 | 243 | }, |
235 | 244 | { |
|
352 | 361 | { |
353 | 362 | "data": { |
354 | 363 | "text/markdown": [ |
| 364 | + "<div class=\"prose\">\n", |
| 365 | + "\n", |
355 | 366 | "---\n", |
356 | 367 | "\n", |
357 | | - "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L76){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 368 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L80){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
358 | 369 | "\n", |
359 | 370 | "#### ThreadPoolExecutor\n", |
360 | 371 | "\n", |
|
367 | 378 | "\n", |
368 | 379 | "```\n", |
369 | 380 | "\n", |
370 | | - "*Same as Python's ThreadPoolExecutor, except can pass `max_workers==0` for serial execution*" |
| 381 | + "*Same as Python's ThreadPoolExecutor, except can pass `max_workers==0` for serial execution*\n", |
| 382 | + "\n", |
| 383 | + "</div>" |
371 | 384 | ], |
372 | 385 | "text/plain": [ |
373 | 386 | "def ThreadPoolExecutor(\n", |
|
425 | 438 | { |
426 | 439 | "data": { |
427 | 440 | "text/markdown": [ |
| 441 | + "<div class=\"prose\">\n", |
| 442 | + "\n", |
428 | 443 | "---\n", |
429 | 444 | "\n", |
430 | | - "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L95){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
| 445 | + "[source](https://github.com/AnswerDotAI/fastcore/blob/main/fastcore/parallel.py#L99){target=\"_blank\" style=\"float:right; font-size:smaller\"}\n", |
431 | 446 | "\n", |
432 | 447 | "#### ProcessPoolExecutor\n", |
433 | 448 | "\n", |
|
441 | 456 | "\n", |
442 | 457 | "```\n", |
443 | 458 | "\n", |
444 | | - "*Same as Python's ProcessPoolExecutor, except can pass `max_workers==0` for serial execution*" |
| 459 | + "*Same as Python's ProcessPoolExecutor, except can pass `max_workers==0` for serial execution*\n", |
| 460 | + "\n", |
| 461 | + "</div>" |
445 | 462 | ], |
446 | 463 | "text/plain": [ |
447 | 464 | "def ProcessPoolExecutor(\n", |
|
570 | 587 | "name": "stdout", |
571 | 588 | "output_type": "stream", |
572 | 589 | "text": [ |
573 | | - "2026-05-02 06:18:54.278913" |
| 590 | + "2026-05-08 13:33:41.853055" |
574 | 591 | ] |
575 | 592 | }, |
576 | 593 | { |
|
598 | 615 | "name": "stdout", |
599 | 616 | "output_type": "stream", |
600 | 617 | "text": [ |
601 | | - "2026-05-02 06:18:54.380686" |
| 618 | + "2026-05-08 13:33:41.954705" |
602 | 619 | ] |
603 | 620 | }, |
604 | 621 | { |
|
626 | 643 | "name": "stdout", |
627 | 644 | "output_type": "stream", |
628 | 645 | "text": [ |
629 | | - "2026-05-02 06:18:54.481676" |
| 646 | + "2026-05-08 13:33:42.055784" |
630 | 647 | ] |
631 | 648 | }, |
632 | 649 | { |
|
654 | 671 | "name": "stdout", |
655 | 672 | "output_type": "stream", |
656 | 673 | "text": [ |
657 | | - "2026-05-02 06:18:54.584016" |
| 674 | + "2026-05-08 13:33:42.156805" |
658 | 675 | ] |
659 | 676 | }, |
660 | 677 | { |
|
682 | 699 | "name": "stdout", |
683 | 700 | "output_type": "stream", |
684 | 701 | "text": [ |
685 | | - "2026-05-02 06:18:54.684495" |
| 702 | + "2026-05-08 13:33:42.258407" |
686 | 703 | ] |
687 | 704 | }, |
688 | 705 | { |
|
760 | 777 | "name": "stdout", |
761 | 778 | "output_type": "stream", |
762 | 779 | "text": [ |
763 | | - "0 2026-05-02 06:18:54.863372 2026-05-02 06:18:54.879976 0.015635678708191197\n", |
764 | | - "1 2026-05-02 06:18:54.863397 2026-05-02 06:18:54.882997 0.019249022668796727\n", |
765 | | - "2 2026-05-02 06:18:54.863403 2026-05-02 06:18:54.887730 0.023758669309642773\n", |
766 | | - "3 2026-05-02 06:18:54.880132 2026-05-02 06:18:54.900268 0.01907637860895647\n", |
767 | | - "4 2026-05-02 06:18:54.883061 2026-05-02 06:18:54.900419 0.01732184794923949\n", |
768 | | - "5 2026-05-02 06:18:54.887778 2026-05-02 06:18:54.903026 0.014917916227832732\n" |
| 780 | + "1 2026-05-08 13:33:42.428080 2026-05-08 13:33:42.432773 0.004103768124250407\n", |
| 781 | + "3 2026-05-08 13:33:42.432916 2026-05-08 13:33:42.434886 0.001710239998176514\n", |
| 782 | + "0 2026-05-08 13:33:42.428053 2026-05-08 13:33:42.445264 0.016137248705558976\n", |
| 783 | + "2 2026-05-08 13:33:42.428088 2026-05-08 13:33:42.454874 0.02574445812549154\n", |
| 784 | + "4 2026-05-08 13:33:42.434937 2026-05-08 13:33:42.454906 0.019200227637860365\n", |
| 785 | + "5 2026-05-08 13:33:42.445306 2026-05-08 13:33:42.477023 0.030652622230735307\n" |
769 | 786 | ] |
770 | 787 | } |
771 | 788 | ], |
|
797 | 814 | "name": "stdout", |
798 | 815 | "output_type": "stream", |
799 | 816 | "text": [ |
800 | | - "0 2026-05-02 06:18:54.926304 2026-05-02 06:18:54.943307 0.015931215772872948\n", |
801 | | - "1 2026-05-02 06:18:55.027303 2026-05-02 06:18:55.033705 0.005639884521666661\n" |
802 | | - ] |
803 | | - }, |
804 | | - { |
805 | | - "name": "stdout", |
806 | | - "output_type": "stream", |
807 | | - "text": [ |
808 | | - "2" |
| 817 | + "0 2026-05-08 13:33:42.501916 2026-05-08 13:33:42.533236 0.031155971298832207\n", |
| 818 | + "1 2026-05-08 13:33:42.601971 2026-05-08 13:33:42.614399 0.0113522631875012\n" |
809 | 819 | ] |
810 | 820 | }, |
811 | 821 | { |
812 | 822 | "name": "stdout", |
813 | 823 | "output_type": "stream", |
814 | 824 | "text": [ |
815 | | - " 2026-05-02 06:18:55.127385 2026-05-02 06:18:55.144286 0.01569178427437135\n", |
816 | | - "3 2026-05-02 06:18:55.227448 2026-05-02 06:18:55.257822 0.02922957194858668\n", |
817 | | - "4 2026-05-02 06:18:55.327466 2026-05-02 06:18:55.337080 0.008768163173784578\n" |
| 825 | + "2 2026-05-08 13:33:42.703034 2026-05-08 13:33:42.734560 0.03126965034014501\n", |
| 826 | + "3 2026-05-08 13:33:42.803025 2026-05-08 13:33:42.810717 0.00664915846504592\n", |
| 827 | + "4 2026-05-08 13:33:42.902539 2026-05-08 13:33:42.916731 0.012804052443942782\n" |
818 | 828 | ] |
819 | 829 | }, |
820 | 830 | { |
821 | 831 | "name": "stdout", |
822 | 832 | "output_type": "stream", |
823 | 833 | "text": [ |
824 | | - "5 2026-05-02 06:18:55.427390 2026-05-02 06:18:55.456955 0.028371390226150824\n" |
| 834 | + "5 2026-05-08 13:33:43.002943 2026-05-08 13:33:43.023861 0.01970723724066066\n" |
825 | 835 | ] |
826 | 836 | } |
827 | 837 | ], |
|
925 | 935 | "output_type": "stream", |
926 | 936 | "text": [ |
927 | 937 | "Traceback (most recent call last):\n", |
928 | | - " File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_35266/1179310912.py\", line 2, in _fail\n", |
| 938 | + " File \"/var/folders/51/b2_szf2945n072c0vj2cyty40000gn/T/ipykernel_12025/1179310912.py\", line 2, in _fail\n", |
929 | 939 | " async def _fail(): raise ValueError(\"this error will be printed\")\n", |
930 | 940 | " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", |
931 | 941 | "ValueError: this error will be printed\n" |
|
1089 | 1099 | "default_code": false, |
1090 | 1100 | "mode": "concise", |
1091 | 1101 | "use_fence": false, |
1092 | | - "use_thinking": true, |
| 1102 | + "use_thinking": false, |
1093 | 1103 | "use_tools": true, |
1094 | 1104 | "ver": 2 |
1095 | 1105 | } |
|
0 commit comments