Commit 2b18909
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 75855a6 commit 2b18909
1 file changed
+52
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
354 | 354 | | |
355 | 355 | | |
356 | 356 | | |
| 357 | + | |
| 358 | + | |
357 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
358 | 363 | | |
359 | 364 | | |
360 | 365 | | |
| |||
506 | 511 | | |
507 | 512 | | |
508 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
509 | 518 | | |
510 | | - | |
| 519 | + | |
511 | 520 | | |
512 | 521 | | |
513 | 522 | | |
| |||
590 | 599 | | |
591 | 600 | | |
592 | 601 | | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
593 | 608 | | |
594 | 609 | | |
595 | 610 | | |
| |||
615 | 630 | | |
616 | 631 | | |
617 | 632 | | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
618 | 669 | | |
619 | 670 | | |
620 | 671 | | |
| |||
0 commit comments