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.

Should delayed objects modify instances of classes?

See original GitHub issue
from dask import delayed
from nose.tools import assert_true

class MyClass(dict):
    pass

@delayed(pure=True)
def foo_dict(arg):
    assert_true(isinstance(arg, dict))

@delayed(pure=True)
def foo_myclass(arg):
    assert_true(isinstance(arg, MyClass))


# works fine
res = foo_dict(MyClass())
res.compute()
# raises an error
res = foo_myclass(MyClass())
res.compute()

This returns an error because when passing through delayed, the instance goes from a MyClass instance to dict.

Is this intended? For my use cases, it doesn’t bother me much, but I want to better understand the inner workings of the delayed object, and what assumptions I can make. If I replaced delayed with a curry instance, this works (of course, now don’t do the last compute step). I’m not sure if this helps narrow things down.

Thanks for the great library!

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
martindurantcommented, Mar 29, 2017

I have checked, and within the function foo, when running in a worker process, arg does have the type MyClass, but id(type(arg)) and id(MyClass) do not match: i.e., presumably deserialization has created two identical class definitions. If you pass the class, it works fine:

    @delayed(pure=True)
    def foo(arg, cls):
        assert_true(isinstance(arg, cls))

res = foo(MyClass(), MyClass)
0reactions
jrmlhermittecommented, Mar 29, 2017

ah yes thanks, I should have seen that. I have noticed that issue in the past. A class defined in the same file code is run is not the same as a class imported (I don’t understand the internals why, but it makes intuitive sense for a namespace safe system).

thanks again

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is delayed initialization good or bad? [closed] - Stack Overflow
When you have an object that is expensive to create, and you want to defer its creation until after other expensive operations have...
Read more >
Best Practices - Dask documentation
Delayed functions only do something if they are computed. You will always need to pass the output to something that eventually calls compute....
Read more >
Delayed Job Best Practices - SitePoint
In this article, I'll cover some of the best practices and tips I apply at work when working with Delayed Job.
Read more >
2.1. Objects - Instances of Classes — AP CSAwesome
2-1-4: How many objects can you create from a class in Java? ... forward 50 pixels instead of 100 in yertle.forward(50); Try changing...
Read more >
Trouble-shooting "Delayed server response" on Change ...
On systems where many Configuration Items are attached to an individual Change Order, there can be very large SQL queries generated which take ......
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