Skip to content

Instantly share code, notes, and snippets.

@samuell
Created October 3, 2013 17:02
Show Gist options
  • Select an option

  • Save samuell/6813220 to your computer and use it in GitHub Desktop.

Select an option

Save samuell/6813220 to your computer and use it in GitHub Desktop.
I tried to run this with: ```` python parallel_test.py --local-scheduler --workers 4 ````
# -*- coding: utf-8 -*-
import luigi
import time
class InData(luigi.ExternalTask):
def __init__(self, chunk_no):
self.chunk_no = chunk_no
def output(self):
return luigi.LocalTarget("input_%d.txt" % self.chunk_no)
class Merged(luigi.Task):
def requires(self):
return [InData(i) for i in xrange(4)]
def output(self):
return luigi.LocalTarget("output.txt")
def run(self):
datas = []
for input in self.input():
with input.open('r') as in_file:
for line in in_file:
time.sleep(1)
datas.append(line.strip())
with self.output().open('w') as out_file:
for data in datas:
print >> out_file, data[0]
if __name__ == '__main__':
luigi.run(main_task_cls=Merged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment