Refactor Lukasz's work

This commit is contained in:
Ian Cordasco 2014-09-13 12:38:25 -05:00
parent 51955f9664
commit 876e283d38

View file

@ -30,6 +30,24 @@ class BaseQReport(pep8.BaseReport):
# Work around http://bugs.python.org/issue10845 # Work around http://bugs.python.org/issue10845
sys.modules['__main__'].__file__ = __file__ sys.modules['__main__'].__file__ = __file__
def _cleanup_queue(self, queue):
while not queue.empty():
queue.get_nowait()
def _put_done(self):
# collect queues
for i in range(self.n_jobs):
self.task_queue.put('DONE')
self.update_state(self.result_queue.get())
def _process_main(self):
if not self._loaded:
# Windows needs to parse again the configuration
from flake8.main import get_style_guide, DEFAULT_CONFIG
get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
for filename in iter(self.task_queue.get, 'DONE'):
self.input_file(filename)
def start(self): def start(self):
super(BaseQReport, self).start() super(BaseQReport, self).start()
self.__class__._loaded = True self.__class__._loaded = True
@ -41,29 +59,18 @@ class BaseQReport(pep8.BaseReport):
def stop(self): def stop(self):
try: try:
# collect queues self._put_done()
for i in range(self.n_jobs):
self.task_queue.put('DONE')
self.update_state(self.result_queue.get())
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
finally: finally:
# cleanup queues to unlock threads # cleanup queues to unlock threads
while not self.result_queue.empty(): self._cleanup_queue(self.result_queue)
self.result_queue.get_nowait() self._cleanup_queue(self.task_queue)
while not self.task_queue.empty():
self.task_queue.get_nowait()
super(BaseQReport, self).stop() super(BaseQReport, self).stop()
def process_main(self): def process_main(self):
if not self._loaded:
# Windows needs to parse again the configuration
from flake8.main import get_style_guide, DEFAULT_CONFIG
get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
try: try:
for filename in iter(self.task_queue.get, 'DONE'): self._process_main()
self.input_file(filename)
except KeyboardInterrupt: except KeyboardInterrupt:
pass pass
finally: finally: