Commit 3f9db41
committed
[IMP] orm: add optional parallelism to iter_browse.create()
Like the same support added to `__attr__` in the parent commit, this can only
be used by callers when it is known that database modifications will be
distinct, not causing concurrency issues or side-effects on the results.
`create` returns an `iter_browse` object for the caller to browse created
records. With the multiprocessing strategy, we make the following changes to
it:
- To support vast amounts of created records in multiprocessing strategy, we
process values in a generator and initialize the returned `iter_browse`
object with it. As this requires the caller of `create` to always
consume/iterate the result (otherwise records will not be created), it is not
applied to the other strategies as it would break existing API.
- make __iter__ yield chunks if strategy is multiprocessing. This way, a caller
can process chunks of freshly created records `for records in
util.iter_browse(strategy="multiprocessing").create(SQLStr)` and since
everything from input to output is a generator, will be perfectly memory
efficient.
- do not pass the logger to the returned `iter_browse` object from `create`, if
the strategy is multiprocessing, because it will lead to interleaved logging
from the input generator and this one when the caller iterates it.1 parent adee6a9 commit 3f9db41
1 file changed
+52
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| 370 | + | |
| 371 | + | |
370 | 372 | | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
371 | 376 | | |
372 | 377 | | |
373 | 378 | | |
| |||
543 | 548 | | |
544 | 549 | | |
545 | 550 | | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
546 | 555 | | |
547 | | - | |
| 556 | + | |
548 | 557 | | |
549 | 558 | | |
550 | 559 | | |
| |||
626 | 635 | | |
627 | 636 | | |
628 | 637 | | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
629 | 644 | | |
630 | 645 | | |
631 | 646 | | |
| |||
651 | 666 | | |
652 | 667 | | |
653 | 668 | | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
| 673 | + | |
| 674 | + | |
| 675 | + | |
| 676 | + | |
| 677 | + | |
| 678 | + | |
| 679 | + | |
| 680 | + | |
| 681 | + | |
| 682 | + | |
| 683 | + | |
| 684 | + | |
| 685 | + | |
| 686 | + | |
| 687 | + | |
| 688 | + | |
| 689 | + | |
| 690 | + | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
654 | 705 | | |
655 | 706 | | |
656 | 707 | | |
| |||
0 commit comments