No simple way to pass initializer for process
See original GitHub issuemultiprocessing.Pool has a handy initializer parameter to pass a callable for setting up per-process resources (database connections, loggers, etc) but joblib doesn’t expose a way to pass this.
I see in 0.10 I can pass a custom multiprocessing context, which I hope I can use to achieve this, but per-process setup is likely something that many users will likely need, so would be good if there was an easier way.
(I’d suggest an initializer parameter to Parallel that’s picked up by MultiprocessingBackend)
Issue Analytics
- State:
- Created 7 years ago
- Reactions:7
- Comments:5
Top Results From Across the Web
how to use initializer to set up my multiprocess pool?
Each worker is in a separate process. Thus, you can use an ordinary global variable. This is not exactly pretty, but it works:...
Read more >Multiprocessing Pool Initializer in Python
You can initialize workers in the process pool by setting the “initializer” argument in the multiprocessing.pool.Pool class constructor.
Read more >Initialize and deinitialize API | Simplygon 9 Documentation
The Simplygon API loader provides an initialization function that must be run ... The easiest way to ensure this is to put the...
Read more >Object initialization - Ruby-Doc.org
So one simple thing we can do is use an initialize method to put default values into all the instance variables, so the...
Read more >Initialization — The Swift Programming Language (Swift 5.7)
Initializers are called to create a new instance of a particular type. In its simplest form, an initializer is like an instance method...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For who is searching for a dirty workaround, I wrote a simple function to inject additional initializer to
Parallelinstance with a Loky backend.Example usage:
Data objects of some complex libraries such as
matlabcan only be loaded after importing the python module. An initializer seems to be the only way to guarantee to load a third party module before the child processes try to unpickle those global data objects.Custom initializers for processes is a must have feature!