Search code examples
pythonmultitaskingluigi

Running parallel tasks SciLuigi


I am stuck with this problem.

I am using SciLuigi framework for task management, but I am not able to run parallel tasks.

class Workflow(sl.WorkflowTask):

    def workflow(self):
        task1 = self.new_task('task 1', Task1)
        task2 = self.new_task('task 2', Task2)
        next_task = sl.new_task('next task', NextTask)
        next_task.in_foo = task1.out_foo
        next_task.in_foo = task2.out_foo
        return next_task

class Task1(sl.Task):
    # No inputs.. just define outputs

    def out_foo(self):
        return sl.TargetInfo(self, 'foo1.txt'))

    def run(self):
        ...

class Task2(sl.Task):
    # No inputs.. just define outputs

    def out_foo(self):
        return sl.TargetInfo(self, 'foo2.txt'))

    def run(self):
        ...

class NextTask(sl.Task):
    # Input
    in_foo = None

    def out_foo(self):
        return sl.TargetInfo(self, 'foo3.txt'))

    def run(self):
        ...

sl.run(main_task_cls=Workflow, cmdline_args=['--workers=2'])

Little help will be appreciate.

Cheers, Diego


Solution

  • Ok I found out the solution.

    In order to run Task1 and Task2 in parallel I have to use two different inputs in NextTask, as follows:

    class Workflow(sl.WorkflowTask):
    
        def workflow(self):
            ...
            next_task.in_foo1 = task1.out_foo
            next_task.in_foo2 = task2.out_foo
            ...
    
    
        class NextTask(sl.Task): 
            # Input
            in_foo1 = None
            in_foo2 = None