fix multiprocessing

This commit is contained in:
Robert Kaussow 2019-04-16 11:33:21 +02:00
parent 37740d1041
commit 040b53f0f1
3 changed files with 17 additions and 4 deletions

View File

@ -1,2 +1,2 @@
- BUGFIXES - BUGFIXES
- Remove multiprocessing due to bad implementation and resulting performance issues - Fix multiprocessing handler causing performance issues

View File

@ -2,6 +2,7 @@
"""Main program.""" """Main program."""
import argparse import argparse
import multiprocessing
import sys import sys
from ansiblelater import LOG from ansiblelater import LOG
@ -38,7 +39,9 @@ def main():
files = config["rules"]["files"] files = config["rules"]["files"]
standards = base.get_standards(config["rules"]["standards"]) standards = base.get_standards(config["rules"]["standards"])
errors = 0 workers = max(multiprocessing.cpu_count() - 2, 2)
p = multiprocessing.Pool(workers)
tasks = []
for filename in files: for filename in files:
lines = None lines = None
candidate = candidates.classify(filename, settings, standards) candidate = candidates.classify(filename, settings, standards)
@ -53,10 +56,15 @@ def main():
LOG.info("Reviewing %s lines %s" % (candidate, lines)) LOG.info("Reviewing %s lines %s" % (candidate, lines))
else: else:
LOG.info("Reviewing all of %s" % candidate) LOG.info("Reviewing all of %s" % candidate)
errors = errors + candidate.review(settings, lines) tasks.append((candidate, settings, lines))
# errors = errors + res
else: else:
LOG.info("Couldn't classify file %s" % filename) LOG.info("Couldn't classify file %s" % filename)
errors = (sum(p.map(_review_wrapper, tasks)))
p.close()
p.join()
if not errors == 0: if not errors == 0:
return_code = 1 return_code = 1
else: else:
@ -65,5 +73,10 @@ def main():
sys.exit(return_code) sys.exit(return_code)
def _review_wrapper(args):
(candidate, settings, lines) = args
return candidate.review(settings, lines)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -102,7 +102,7 @@ class Candidate(object):
return target_standards return target_standards
def review(self, settings, lines=0): def review(self, settings, lines=None):
errors = 0 errors = 0
for standard in self.standards: for standard in self.standards: