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.

Silent recalculation of result when trying to cache a lambda with dill

See original GitHub issue

I have @memory.cache’d a function that returns a lambda expression. This is not possible to pickle, which makes joblib not cache the result and instead rerun it everytime. dill however is able to pickle such functions, and so I set it as a loky pickler. Yet, the function is still not cached and rerun everytime.

This took me quite a while to find out in two ways. First, to see that if pickling fails, joblib silences this error and does not cache. To mitigate, I use dill as a pickler but that still fails silently.

I would expect

  • joblib to crash if it cannot pickle a result, instead of silently going on,
  • joblib to crash if I explicitly set a pickler, but that is apparently not used.

I am using joblib-1.1.0, dill-0.3.4 Python 3.9.9 on Mac OS Monterey, M1. Here is what I run:

from joblib.memory import Memory
from joblib.externals.loky import set_loky_pickler
set_loky_pickler('dill')

memory = Memory('./cache')

@memory.cache
def do_stuff():
    return lambda: 2


x = do_stuff()

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
GaelVaroquauxcommented, Feb 18, 2022

I hence take away from the conversation that there currently is no way to make joblib work with lambdas.

Not with regards to the outputs of functions in mem.cache.

Doing so would require quite some work in numpy_pickle, I suppose.

I would agree. We would probably rather use cloud_pickle than dill, because we really in cloud_pickle elsewhere.

0reactions
bayerjcommented, Feb 18, 2022

Ok, excuse my misunderstanding and thank you for your patience.

I hence take away from the conversation that there currently is no way to make joblib work with lambdas. Doing so would require quite some work in numpy_pickle, I suppose.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Caching data and configuration settings with AWS Lambda ...
This reduces function latency and costs. This post shows how to build both a data and configuration cache using DynamoDB, Parameter Store, and ......
Read more >
Can Python pickle lambda functions? - Stack Overflow
try pickle.loads from an other script; I think you pickle the reference to lambda wich, in the same scope, is preserved in memory...
Read more >
Lambda: What is the simplest way to cache data ... - Reddit
I'd like to cache the results of some queries, in order to improve performance. For example: count queries, user permission checks, etc.
Read more >
InfiniCache: Distributed Cache on Top of AWS Lambda (paper ...
Cloud providers try to reuse compute instances for multiple subsequent requests. The price of bootstrapping new instances is too high to pay for ......
Read more >
the of and to a in for is on s that by this with i you it not
... right j type because local those using results office education national g ... put computers journal reports try welcome images central president...
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