Ask Your Question

Revision history [back]

Can I use @parallel for class methods?

I would like to be able to evaluate some class methods in parallel. For example:

class PTest(SageObject):
    def meth0(self,n):
        return n
    @parallel
    def meth1(self,n):
        "long and complicated class method"
        sleep(2)
        return prime_pi(n)

sage: L = [1000,2000,3000,4000,5000]
sage: T = PTest()
sage: T.meth1(L[0])
168
sage: r = T.meth1(L)
...
TypeError: an integer is required

Note that @parallel does work fine if I define meth1 outside of the class, and introspection T.meth1? indicates that the decorator has been applied to it. So I don't understand what else I should do; any ideas?

click to hide/show revision 2
I'm not sure I've used the terms "class method" or "instance method" totally accurately

Can I use @parallel for class class/instance methods?

I would like to be able to evaluate some class methods in parallel. For example:

class PTest(SageObject):
    def meth0(self,n):
        return n
    @parallel
    def meth1(self,n):
        "long and complicated class method"
        sleep(2)
        return prime_pi(n)

sage: L = [1000,2000,3000,4000,5000]
sage: T = PTest()
sage: T.meth1(L[0])
168
sage: r = T.meth1(L)
...
TypeError: an integer is required

Note that @parallel does work fine if I define meth1 outside of the class, and introspection T.meth1? indicates that the decorator has been applied to it. So I don't understand what else I should do; any ideas?