Luigi: Decrease_running_resources to zero not working as expected

Created on 9 Nov 2018  路  4Comments  路  Source: spotify/luigi

I attempted to do the following with the expectation that after 10 seconds the first task would release the resource and allow the second task to run in parallel:

import luigi


class Y(luigi.Task):
    wait = luigi.IntParameter(default=10)
    n = luigi.IntParameter()

    resources = ({'A': 1})

    def output(self):
        return luigi.LocalTarget('out{}.txt'.format(self.n))

    def run(self):
        sleep(self.wait)
        self.decrease_running_resources({'A': 0})
        sleep(self.wait)
        f = self.output().open('w')
        f.close()


class Z(luigi.WrapperTask):
    tasks = [Y(n=x) for x in range(20)]

    def requires(self):
        yield self.tasks
$ luigid
$ luigi --module x Z --workers 20

Most helpful comment

"Decrease" naturally acts as "minus". I think you made this oversight. You probably wanted

self.decrease_running_resources({'A': 1})

Happy plumbing! :)

All 4 comments

I have zero experience with luigi resources. I could look into this more, but the time is not available at this moment.

Looks like @riga and @daveFNbuck have contributed to this feature. Maybe they can help!

"Decrease" naturally acts as "minus". I think you made this oversight. You probably wanted

self.decrease_running_resources({'A': 1})

Happy plumbing! :)

Anyway I could help by updating the documentation to make it more clear?

In general, PRs to improve Luigi documentation clarity are invited :) @tiamot

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DanCardin picture DanCardin  路  7Comments

riga picture riga  路  7Comments

citynorman picture citynorman  路  6Comments

alfonsomhc picture alfonsomhc  路  3Comments

AndresUrregoAngel picture AndresUrregoAngel  路  4Comments