Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid running a specific task simultaneously in Luigi with multiple workers

I use Luigi to build data analysis tasks including plotting by matplotlib.

It seems concurrent runs of matplotlib plotting causes a problem, which causes returning from the task prematurely, doing nothing, for some reason. (Looks like this is the problem with matplotlib, though I might be wrong.)

To solve this issue, I want to avoid running multiple workers for only that plotting task simultaneously, while running other tasks in multiple workers. How can I do that?

like image 416
Hiro Avatar asked Oct 30 '15 06:10

Hiro


Video Answer


1 Answers

You can use resources for that. On /etc/luigi/client.cfg configure a resource like:

[resources]
mathplotlib: 1

And then, modify your task this way:

class MyTask(luigi.Task):
    resources = {"mathplotlib": 1}

If you have muliple machines running luigi workers and you want that only one worker across all machines may be using a given resource, then you can take a look a this solution.

like image 131
matagus Avatar answered Oct 09 '22 04:10

matagus