mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-10 23:04:18 +00:00
Fix SIGINT when running on multiprocessing
^C was making the script hang (few scenarios possible). This patch makes sure that the queue operations won't block forever. Potentially related to #167
This commit is contained in:
parent
e6cb9528d3
commit
cbba9faf9e
1 changed files with 27 additions and 12 deletions
|
|
@ -36,23 +36,38 @@ class BaseQReport(pep8.BaseReport):
|
||||||
# spawn processes
|
# spawn processes
|
||||||
for i in range(self.n_jobs):
|
for i in range(self.n_jobs):
|
||||||
p = multiprocessing.Process(target=self.process_main)
|
p = multiprocessing.Process(target=self.process_main)
|
||||||
|
p.daemon = True
|
||||||
p.start()
|
p.start()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
# collect queues
|
try:
|
||||||
for i in range(self.n_jobs):
|
# collect queues
|
||||||
self.task_queue.put('DONE')
|
for i in range(self.n_jobs):
|
||||||
self.update_state(self.result_queue.get())
|
self.task_queue.put('DONE')
|
||||||
super(BaseQReport, self).stop()
|
self.update_state(self.result_queue.get())
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print('... stopped')
|
||||||
|
finally:
|
||||||
|
# cleanup queues to unlock threads
|
||||||
|
while not self.result_queue.empty():
|
||||||
|
self.result_queue.get_nowait()
|
||||||
|
while not self.task_queue.empty():
|
||||||
|
self.task_queue.get_nowait()
|
||||||
|
|
||||||
|
super(BaseQReport, self).stop()
|
||||||
|
|
||||||
def process_main(self):
|
def process_main(self):
|
||||||
if not self._loaded:
|
try:
|
||||||
# Windows needs to parse again the configuration
|
if not self._loaded:
|
||||||
from flake8.main import get_style_guide, DEFAULT_CONFIG
|
# Windows needs to parse again the configuration
|
||||||
get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
|
from flake8.main import get_style_guide, DEFAULT_CONFIG
|
||||||
for filename in iter(self.task_queue.get, 'DONE'):
|
get_style_guide(parse_argv=True, config_file=DEFAULT_CONFIG)
|
||||||
self.input_file(filename)
|
for filename in iter(self.task_queue.get, 'DONE'):
|
||||||
self.result_queue.put(self.get_state())
|
self.input_file(filename)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
self.result_queue.put(self.get_state())
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
return {'total_errors': self.total_errors,
|
return {'total_errors': self.total_errors,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue