use of TaskGenerator inside a class fails

12 views
Skip to first unread message

bank...@math.tu-berlin.de

unread,
Jul 6, 2016, 2:17:23 PM7/6/16
to jug-users
Hi,

I'd like to use jug inside a class, i.e., tasks are created inside a __call__ method of a class. However, running jug fails with the error, that __call__ needs 2 arguments, but only one is provided. This function runs perfectly fine, when its not decorated with @TaskGenerator, so somehow 'self' is not being passed to the function.

Currently I am using a dirty hack, so please add support for class methods.

Luis Pedro Coelho

unread,
Jul 6, 2016, 3:59:23 PM7/6/16
to jug-...@googlegroups.com
My impression of that you are trying is an unsupported use. Why not simply have a regular function?

Luis
--
Luis Pedro Coelho

bank...@math.tu-berlin.de

unread,
Jul 6, 2016, 5:00:07 PM7/6/16
to jug-users
I've been writing my whole code object-oriented so far. The actual task that's paralelizable happens after lots of initializations. Having a regular function is not that 'simple', I need a whole copy of my workspace. I don't want to mess up my structure by using global variables or similar.   

Luis Pedro Coelho

unread,
Jul 6, 2016, 5:09:15 PM7/6/16
to jug-...@googlegroups.com
You can always write a one line function that calls your method.

Jug does well in an object-based style, but it's not designed for
old-school OOP.

Luis

--
Luis Pedro Coelho | EMBL | http://luispedro.org
My blog: http://metarabbit.wordpress.com

On Wed, 6 Jul 2016, at 11:00 PM, bank...@math.tu-berlin.de wrote:
> I've been writing my whole code object-oriented so far. The actual task
> that's paralelizable happens after lots of initializations. Having a
> regular function is not that 'simple', I need a whole copy of my
> workspace.
> I don't want to mess up my structure by using global variables or
> similar.
>
>
> On Wednesday, July 6, 2016 at 3:59:23 PM UTC-4, luispedro wrote:
> >
> > My impression of that you are trying is an unsupported use. Why not simply
> > have a regular function?
> >
> > Luis
> >
> > On July 6, 2016 8:14:00 PM GMT+02:00, bank...@math.tu-berlin.de
> > <javascript:> wrote:
> >>
> >> Hi,
> >>
> >> I'd like to use jug inside a class, i.e., tasks are created inside a
> >> __call__ method of a class. However, running jug fails with the error, that
> >> __call__ needs 2 arguments, but only one is provided. This function runs
> >> perfectly fine, when its not decorated with @TaskGenerator, so somehow
> >> 'self' is not being passed to the function.
> >>
> >> Currently I am using a dirty hack, so please add support for class
> >> methods.
> >>
> >>
> > --
> > Luis Pedro Coelho
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "jug-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jug-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

bank...@math.tu-berlin.de

unread,
Jul 6, 2016, 5:31:42 PM7/6/16
to jug-users
I could. But then either the user would have to cope with all the magic or I would end up not using classes. I'm basically calling a method in my class, and inside that method I do initialization and finally call map(self, parameters). The problem is not bound to the __call__ method, it's happening with all class methods.
Or did you mean something else by writing a one line function that calls my method?

Luis Pedro Coelho

unread,
Jul 6, 2016, 5:41:33 PM7/6/16
to jug-...@googlegroups.com
For a normal method, you can replace

obj.f(1, 2,3)

by

call_f(obj, 1, 2, 3)

*

You can also always just go back to the Task interface not relying on
the TaskGenerator magic:

from jug import Task
class MyObject(object):
def __init__(self):
self.params = [1,2,3]

def f(self, arg):
# real work goes here

def __call__(self, arg):
return Task(call_f, self, arg)

Luis Pedro Coelho | EMBL | http://luispedro.org
My blog: http://metarabbit.wordpress.com

bank...@math.tu-berlin.de

unread,
Jul 7, 2016, 8:22:51 AM7/7/16
to jug-users
Since I'm using map for calling f the first option is not that nice (but truely) works. The second one seems to be the way to go for me. Anyway, it would be good to have support for what I was trying to do or at least raise a meaningful error. Thanks for your help!
Reply all
Reply to author
Forward
0 new messages