question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pickle error in Parallel

See original GitHub issue

Hey,

I get an error with 0.12 that didn’t occur in 0.11

snippet of code: num_cores = multiprocessing.cpu_count() chunks = _get_chunks(ids, 100) logger.info('cores: {0}, chunks: {1}'.format(num_cores, len(chunks))) Parallel(n_jobs=num_cores)(delayed(_clean_text)(c) for c in chunks)

The resulting error is: Cannot pickle files that are not opened for reading: a

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
ogriselcommented, Jul 2, 2018

@EloyRoura the point of using the loky backend in joblib is to replace the multiprocessing.Pool backend. With the loky backend you no longer need to protect your code with the if __name__ == '__main__' condition.

Here is an example:

>>> from joblib import Parallel, delayed
>>> def some_funtion(p):
...     return p*p
... 
>>> parameters = range(10)
>>> num_cores=4#multiprocessing.cpu_count()
>>> Parallel(n_jobs=num_cores, verbose=1)(delayed(some_funtion)(p) for p in parameters)
[Parallel(n_jobs=4)]: Using backend LokyBackend with 4 concurrent workers.
[Parallel(n_jobs=4)]: Done  10 out of  10 | elapsed:    0.4s finished
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
2reactions
lestevecommented, Jun 26, 2018

For completeness, here is a stand-alone snippet for the pymc3-related issue:

import numpy as np

import pymc3 as pm

rng = np.random.RandomState(0)
count_data = rng.randint(1, 70, 100).astype(dtype=np.float64)
n_count_data = len(count_data)

with pm.Model() as model:
    alpha = 1.0/count_data.mean()  # Recall count_data is the
                                   # variable that holds our txt counts
    lambda_1 = pm.Exponential("lambda_1", alpha)
    lambda_2 = pm.Exponential("lambda_2", alpha)
    
    tau = pm.DiscreteUniform("tau", lower=0, upper=n_count_data - 1)

with model:
    step = pm.Metropolis()
    trace = pm.sample(5, tune=10,step=step)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Pickle error when making parallel version of map function in ...
I'm trying to use it the same exact way as I would use the regular map function. Why does this happen? How can...
Read more >
Serialization of un-picklable objects - Joblib
First, define functions which cannot be pickled with the standard pickle protocol. They cannot be serialized with pickle because they are defined in...
Read more >
Parallel sampling without pickle in version 4.0.0b3 - v4
I'm using a black-box likelihood and run into an error when parallel sampling. version 4.0.0b3. Traceback (most recent call last): File ...
Read more >
parallel test running throwing pickleError - Google Groups
Setting a breakpoint inside that method around the error message should give you the required pointers to fix the import and thus the...
Read more >
Multiprocessing and Pickle, How to Easily fix that?
However, the multiprocess tasks can't be pickled; it would raise an error failing to pickle. That's because when dividing a single task over ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found