| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Sorry, something went wrong.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead. |
Sorry, something went wrong.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead. |
Sorry, something went wrong.
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead. |
Sorry, something went wrong.
|
Please open an issue first for this one (I don't know if it's something that is discussed in the sprint). |
Sorry, something went wrong.
|
Previous discussion for executor: #74028 |
Sorry, something went wrong.
|
@picnixz thanks. The issue already exists, I will add more detailed description here soon, just wanted to run all tests for now. |
Sorry, something went wrong.
|
Thanks! I'm actually adding the GH issue inthe title so that we can backref it easily. |
Sorry, something went wrong.
|
I'm adding a skipnews just for the CI otherwise you'll get a notification saying that the labels are incorrect. |
Sorry, something went wrong.
| the *iterables* pauses until a result is yielded from the buffer. | ||
| To fully utilize pool's capacity, set *buffersize* to the number of | ||
| processes in pool (to consume *iterable* as you go) or even higher | ||
| (to prefetch *buffersize - processes* arguments). |
There was a problem hiding this comment.
I was questioning myself whether we should also describe the difference in buffersize usefulness
between multiprocessing.Pool and multiprocessing.ThreadPool, I would be glad to hear an opinion on that – what do you think?
This feature is more useful with multiprocessing.ThreadPool class, where user can pass generator as iterable. multiprocessing.Pool with processes currently can't accept generators as they aren't picklable, so the user still needs to pass iterable as, for example, list, which is O(n). However, there is another huge benefit to using it – tasks will also be submitted lazily (while user iterates over results), and not-needed-yet results won't stack up in memory. So I think the feature is useful for any kind of pool and docs shouldn't suggest to use it specifically for threads.
Sorry, something went wrong.
|
Hello @ambv - we've been talking about this PR during EuroPython sprints a week ago and I wanted to let you know that it's ready (as you said you would review it). Hello @gpshead - I'm also glad to say it's ready, but we've already been discussing the idea with Łukasz so you can agree how do we proceed further. Thanks in advance. |
Sorry, something went wrong.
|
This PR is stale because it has been open for 30 days with no activity. |
Sorry, something went wrong.
…e-to-multiprocessing Note: I also had to add 1 '=' character to `Doc/whatsnew/3.16.rst` because check-merge-conflict pre-commit hook was detecting legit markdown syntax as a merge conflict string.
Documentation build overview15 files changed · ± 15 modified ± Modified |
Sorry, something went wrong.
There was a problem hiding this comment.
Thank you for fixing this!
I think the new argument needs to be keyword-only -- passing it positionally would be quite confusing.
I'm afraid that as another reviewer, I'll add a few more smaller issues. Those aren't blocking, though.
Sorry, something went wrong.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
There was a problem hiding this comment.
This looks good to me!
I'm not an expert on this module, so I'll give others a chance to chime in.
I'll merge next week if there are no objections.
Sorry, something went wrong.
|
Sorry for the delay, I'm still catching up after EuroPython :) |
Sorry, something went wrong.
…ultiprocessing.pool` (pythonGH-136871) The new argument allows consuming the input iterator lazily, potentially saving memory, and allowing long/infinite iterators. It mirrors the *buffersize* argument to `concurrent.futures.Executor.map` that was added in 3.14. Co-authored-by: Oleksandr Baltian <oleksandr.baltian@maklai.com.ua> Co-authored-by: Petr Viktorin <encukou@gmail.com> Co-authored-by: Sasha Baltian <sasha.baltian@hyperexponential.com>
| Back | FazBrowse Home | New Git URL |
Context recap (#64192)
Let's consider that we have an input iterable and N = len(iterable).
Current multiprocessing.Pool.imap and multiprocessing.Pool.imap_unordered are O(N) in space (unecessarily expensive on large iterables, completely impossible to use on infinite iterables):
The call results: Iterator = pool.imap(func, iterable) iterates over all the elements of the iterable, submitting N tasks to the pool (results are collected into a list of size N). Following calls to next(results) take the oldest result from the list (FIFO) (waiting for it if not available yet) and return it.
Proposal: add an optional buffersize param
With this proposal, the call results: Iterator = pool.imap(func, iterable, buffersize=b) will iterate only over the first b elements of iterable (acquiring buffersize semaphore while iterating), submitting b tasks to worker threads and then will return the results iterator.
Calls to next(results) will release buffersize semaphore (allowing task_handler thread to get the next input element from iterable to submit a new task to a worker thread) and then return the result.
buffersize semaphores from iterators not exhausted yet are also being released on pool termination to avoid deadlocks.
Benefits:
Feature history
buffersize support has been recently merged into concurrent.futures.Executor.map implementation (#125663) and many code/test/doc parts are based on ones from there to ensure consistency between modules.
I want to thank authors of that PR for the references.
Links: