mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-09 22:34:17 +00:00
Add naive multiprocessing support
This commit is contained in:
parent
d222fcb9e1
commit
07b9ffbeb9
2 changed files with 46 additions and 13 deletions
|
|
@ -116,12 +116,27 @@ class Manager(object):
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""Start checking files."""
|
"""Start checking files."""
|
||||||
pass
|
LOG.info('Making checkers')
|
||||||
# for i in range(self.jobs or 0):
|
self.make_checkers()
|
||||||
# proc = multiprocessing.Process(target=self.process_files)
|
if not self.using_multiprocessing:
|
||||||
# proc.daemon = True
|
return
|
||||||
# proc.start()
|
|
||||||
# self.processes.append(proc)
|
LOG.info('Populating process queue')
|
||||||
|
for checker in self.checkers:
|
||||||
|
self.process_queue.put(checker)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
"""Stop checking files."""
|
||||||
|
if not self.using_multiprocessing:
|
||||||
|
return
|
||||||
|
|
||||||
|
LOG.info('Notifying process workers of completion')
|
||||||
|
for i in range(self.jobs or 0):
|
||||||
|
self.process_queue.put('DONE')
|
||||||
|
|
||||||
|
LOG.info('Joining process workers')
|
||||||
|
for process in self.processes:
|
||||||
|
process.join()
|
||||||
|
|
||||||
def make_checkers(self, paths=None):
|
def make_checkers(self, paths=None):
|
||||||
# type: (List[str]) -> NoneType
|
# type: (List[str]) -> NoneType
|
||||||
|
|
@ -137,14 +152,31 @@ class Manager(object):
|
||||||
if utils.fnmatch(filename, filename_patterns)
|
if utils.fnmatch(filename, filename_patterns)
|
||||||
]
|
]
|
||||||
|
|
||||||
def run(self):
|
def _run_checks_from_queue(self):
|
||||||
"""Run checks.
|
LOG.info('Running checks in parallel')
|
||||||
|
for checker in iter(self.process_queue.get, 'DONE'):
|
||||||
TODO(sigmavirus24): Get rid of this
|
LOG.debug('Running checker for file "%s"', checker.filename)
|
||||||
"""
|
|
||||||
for checker in self.checkers:
|
|
||||||
checker.run_checks()
|
checker.run_checks()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""Run all the checkers.
|
||||||
|
|
||||||
|
This handles starting the process workers or just simply running all
|
||||||
|
of the checks in serial.
|
||||||
|
"""
|
||||||
|
if self.using_multiprocessing:
|
||||||
|
LOG.info('Starting process workers')
|
||||||
|
for i in range(self.jobs or 0):
|
||||||
|
proc = multiprocessing.Process(
|
||||||
|
target=self._run_checks_from_queue
|
||||||
|
)
|
||||||
|
proc.daemon = True
|
||||||
|
proc.start()
|
||||||
|
self.processes.append(proc)
|
||||||
|
else:
|
||||||
|
for checker in self.checkers:
|
||||||
|
checker.run_checks()
|
||||||
|
|
||||||
def is_path_excluded(self, path):
|
def is_path_excluded(self, path):
|
||||||
# type: (str) -> bool
|
# type: (str) -> bool
|
||||||
"""Check if a path is excluded.
|
"""Check if a path is excluded.
|
||||||
|
|
|
||||||
|
|
@ -254,7 +254,6 @@ class Application(object):
|
||||||
arguments=self.args,
|
arguments=self.args,
|
||||||
checker_plugins=self.check_plugins,
|
checker_plugins=self.check_plugins,
|
||||||
)
|
)
|
||||||
self.file_checker_manager.make_checkers()
|
|
||||||
|
|
||||||
def run(self, argv=None):
|
def run(self, argv=None):
|
||||||
# type: (Union[NoneType, List[str]]) -> NoneType
|
# type: (Union[NoneType, List[str]]) -> NoneType
|
||||||
|
|
@ -266,7 +265,9 @@ class Application(object):
|
||||||
self.make_notifier()
|
self.make_notifier()
|
||||||
self.make_guide()
|
self.make_guide()
|
||||||
self.make_file_checker_manager()
|
self.make_file_checker_manager()
|
||||||
|
self.file_checker_manager.start()
|
||||||
self.file_checker_manager.run()
|
self.file_checker_manager.run()
|
||||||
|
self.file_checker_manager.stop()
|
||||||
|
|
||||||
|
|
||||||
def main(argv=None):
|
def main(argv=None):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue