Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

This isn't quite an answer, but hopefully will help.

Niles, look at the traceback more carefully.

    114                 return self.p_iter(f, (normalize_input(a) for a in args[0]))
    115             else:
--> 116                 return f(*args, **kwds)
    117         return g
    118

Clearly it's gotten the parallel, as you say. But the whole thing is

# Construct the wrapper parallel version of the function we're wrapping.
# We may rework this so g is a class instance, which has the plus that
# we can query g for how it works, etc.
def g(*args, **kwds):
    if len(args) > 0 and isinstance(args[0], (list, types.GeneratorType)):
        return self.p_iter(f, (normalize_input(a) for a in args[0]))
    else:
        return f(*args, **kwds)
return g

If I insert a print statement (print args) before the if/else, I get

sage: T.meth1(L[0])
(<class '__main__.PTest'>, 1000)
168
sage: r = T.meth1(L)
(<class '__main__.PTest'>, [1000, 2000, 3000, 4000, 5000])

Does this help?

This isn't quite an answer, but hopefully will help.

Niles, look at the traceback more carefully.

    114                 return self.p_iter(f, (normalize_input(a) for a in args[0]))
    115             else:
--> 116                 return f(*args, **kwds)
    117         return g
    118

Clearly it's gotten the parallel, as you say. But the whole thing is

# Construct the wrapper parallel version of the function we're wrapping.
# We may rework this so g is a class instance, which has the plus that
# we can query g for how it works, etc.
def g(*args, **kwds):
    if len(args) > 0 and isinstance(args[0], (list, types.GeneratorType)):
        return self.p_iter(f, (normalize_input(a) for a in args[0]))
    else:
        return f(*args, **kwds)
return g

If I insert a print statement (print args) before the if/else, if/else as well as print statements about which branch I take, I get

sage: T.meth1(L[0])
(<class '__main__.PTest'>, 1000)
second branch
168
sage: r = T.meth1(L)
(<class '__main__.PTest'>, [1000, 2000, 3000, 4000, 5000])
second branch
---------------------------------------------------------
TypeError

Does this help?

It's never even reaching the point of the iterator, because the first item in args is not iterable, but the class itself. I don't know how to fix this, except by adding a case in the if statement, but I have no idea whether that would break anything else.