Created
October 3, 2013 17:02
-
-
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
````
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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