multiprocessing_generator | Prefetch elements from a Python generator
kandi X-RAY | multiprocessing_generator Summary
kandi X-RAY | multiprocessing_generator Summary
A library to prefetch items from a Python generator in the background, using a separate process. Up to 100 elements ahead of what is consumed will be fetched by the generator in the background, which is useful when the producer and the consumer do not use the same resources (for instance network vs. CPU). The generator handles exceptions and more serious failures transparently. Distributed under the MIT license.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of multiprocessing_generator
multiprocessing_generator Key Features
multiprocessing_generator Examples and Code Snippets
Community Discussions
Trending Discussions on multiprocessing_generator
QUESTION
I'm found the module multiprocessing_generator. I tried that module with the code below :
...ANSWER
Answered 2019-Jan-02 at 14:33multiprocessing_generator
relies on the multiprocessing module using the 'fork'
start method, because it assumes that the wrapped
nested function (defined in ParallelGenerator
's __init__
) can be passed as the target
of a multiprocessing.Process
object. On a fork
ing based platform, this is fine; the child process inherits the complete state of the parent (with a few small exceptions like threads), so it has equal access to the wrapped
nested function (it inherited an exact copy after all).
Problem is, on Windows, the only available start method is 'spawn'
, which requires the target
(and all arguments) to be pickle
able (it pickle
s them, sends them to the child over IPC, and reconstructs them there), and nested functions are never pickle
able (pickle
ing a function involves pickling its qualified name to be imported and used on the other side, and the qualified name of a nested function involves unimportable components, in this case, pickle
ing ParallelGenerator.__init__..wrapped
fails because is clearly not an importable name).
Basically, multiprocessing_generator
only works on UNIX-like systems, and only if you're using the default start method ('fork'
); if you called set_start_method
with some other value ('forkserver'
or 'spawn'
), multiprocessing_generator
can't be made to work.
While this is a bug, it's not a particularly critical bug in most cases; there is very little benefit to the module if the generator must have its values pickled, because most such generators either aren't pickle
able themselves (e.g. most file-like objects) or pickle
ing them involves running them to completion (in which case you've lost all your parallelism).
Sorry, but the simple answer here is: Don't use multiprocessing_generator
on Windows.
That said, if your generator is I/O-bound, you might be able to benefit from the module by importing it, then immediately monkey-patching it to replace all multiprocessing
components it relies on with their equivalent multiprocessing.dummy
names (which are backed by threads, and don't rely on pickling), e.g.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install multiprocessing_generator
You can use multiprocessing_generator like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page