Should delayed objects modify instances of classes?
See original GitHub issuefrom 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:
- Created 7 years ago
- Comments:11 (11 by maintainers)
Top 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 >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 FreeTop 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
Top GitHub Comments
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: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