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.

Log when memory fails due to unpicklable function output

See original GitHub issue

I just spent hours trying to find out why my function didn’t get cached when using @memory.cache. It turns out the reason was that the function returned an object where pickle threw an exception when trying to pickle it to disk.

This exception was silently swallowed in _store_backends.py:

    def dump_item(self, path, item, verbose=1):
        """Dump an item in the store at the path given as a list of
           strings."""
        try:
            item_path = os.path.join(self.location, *path)
            if not self._item_exists(item_path):
                self.create_location(item_path)
            filename = os.path.join(item_path, 'output.pkl')
            if verbose > 10:
                print('Persisting in %s' % item_path)

            def write_func(to_write, dest_filename):
                with self._open_item(dest_filename, "wb") as f:
                    numpy_pickle.dump(to_write, f,
                                      compress=self.compress)

            self._concurrency_safe_write(item, filename, write_func)
        except:  # noqa: E722
            " Race condition in the creation of the directory "

It would be great if at least a log message would be generated along the lines of “function XY could not be cached due to unpicklable function result”, even if this is just logged at a high verbosity level.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Nieliuscommented, Nov 8, 2022

I also just spent several hours trying to find out why my output wasn’t being cached. I’ve created a PR: https://github.com/joblib/joblib/pull/1359

It’s just 2 lines, but it does the job, and maybe we can then close this issue that has been open for 3 years now?

0reactions
tnielenscommented, Nov 11, 2021

Same here, I spent several hours testing different changes and reading the documentation to figure out why my output wasn’t cached and what I did wrong. An error message in the log would have been quite helpful 😃.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python - using a process pool with an unpicklable object
My issue is - if I want to have this code snippet inside a class, or just inside a method, it wouldn't work,...
Read more >
17.2. multiprocessing — Process-based parallelism
The multiprocessing.sharedctypes module provides functions for allocating ctypes objects from shared memory which can be inherited by child processes. Note.
Read more >
Pickling xp objects - FICO Community
In python xp.var objects have a __reduce__ function, but still return an unpicklable error on Windows (Not tested on linux).
Read more >
Multiprocessing and Pickle, How to Easily fix that?
Sign up for Medium and get an extra one ... would fail because lambda cannot pickle as we mentioned before. ... The output...
Read more >
pickle — Python object serialization — Python 3.11.1 ...
JSON is a text serialization format (it outputs unicode text, although most of the ... Error raised when an unpicklable object is encountered...
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