Commit 8fc8005
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 a5b7dbc commit 8fc8005
1 file changed
+60
-18
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 | | |
| |||
522 | 527 | | |
523 | 528 | | |
524 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
525 | 534 | | |
526 | | - | |
| 535 | + | |
527 | 536 | | |
528 | 537 | | |
529 | 538 | | |
| |||
593 | 602 | | |
594 | 603 | | |
595 | 604 | | |
596 | | - | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
597 | 608 | | |
598 | | - | |
| 609 | + | |
| 610 | + | |
599 | 611 | | |
600 | | - | |
601 | | - | |
| 612 | + | |
| 613 | + | |
602 | 614 | | |
603 | 615 | | |
604 | | - | |
605 | | - | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
606 | 625 | | |
| 626 | + | |
| 627 | + | |
| 628 | + | |
| 629 | + | |
| 630 | + | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
607 | 636 | | |
608 | | - | |
609 | | - | |
610 | | - | |
611 | | - | |
612 | | - | |
613 | | - | |
614 | | - | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
615 | 654 | | |
616 | | - | |
617 | 655 | | |
618 | | - | |
619 | | - | |
620 | | - | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
621 | 663 | | |
622 | 664 | | |
623 | 665 | | |
| |||
0 commit comments