Skip to content

Commit 9b8f038

Browse files
committed
Tidy up last few bits for performance improvement
1 parent 109f5f8 commit 9b8f038

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

CONTRIBUTORS.txt

+1
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,4 @@ Contributors (by order of appearance) :
2525
- Tyrel Souza
2626
- Corey Farwell
2727
- Michael Penkov
28+
- Anthony Sottile

docs/source/release-notes/3.3.0.rst

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
You can view the `3.3.0 milestone`_ on GitLab for more details.
55

6+
- Dramatically improve the performance of Flake8 (`GitLab!156`_)
7+
68
- Fix problem where hooks should only check \*.py files. (See also
79
`GitLab#268`_)
810

@@ -14,3 +16,5 @@ You can view the `3.3.0 milestone`_ on GitLab for more details.
1416
https://gitlab.com/pycqa/flake8/milestones/16
1517
.. _GitLab#268:
1618
https://gitlab.com/pycqa/flake8/issues/268
19+
.. _GitLab!156:
20+
https://gitlab.com/pycqa/flake8/merge_requests/156

src/flake8/checker.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,6 @@ def __init__(self, style_guide, arguments, checker_plugins):
9292
raise
9393
self.using_multiprocessing = False
9494

95-
@staticmethod
96-
def _cleanup_queue(q):
97-
while not q.empty():
98-
q.get_nowait()
99-
10095
def _process_statistics(self):
10196
for checker in self.checkers:
10297
for statistic in defaults.STATISTIC_NAMES:
@@ -279,10 +274,15 @@ def run_parallel(self):
279274
"""Run the checkers in parallel."""
280275
final_results = collections.defaultdict(list)
281276
final_statistics = collections.defaultdict(dict)
282-
for ret in self.pool.imap_unordered(
283-
_run_checks, self.checkers,
284-
chunksize=_pool_chunksize(len(self.checkers), self.jobs),
285-
):
277+
pool_map = self.pool.imap_unordered(
278+
_run_checks,
279+
self.checkers,
280+
chunksize=calculate_pool_chunksize(
281+
len(self.checkers),
282+
self.jobs,
283+
),
284+
)
285+
for ret in pool_map:
286286
filename, results, statistics = ret
287287
final_results[filename] = results
288288
final_statistics[filename] = statistics
@@ -620,7 +620,7 @@ def _pool_init():
620620
signal.signal(signal.SIGINT, signal.SIG_IGN)
621621

622622

623-
def _pool_chunksize(num_checkers, num_jobs):
623+
def calculate_pool_chunksize(num_checkers, num_jobs):
624624
"""Determine the chunksize for the multiprocessing Pool.
625625
626626
- For chunksize, see: https://docs.python.org/3/library/multiprocessing.html#multiprocessing.pool.Pool.imap # noqa

0 commit comments

Comments
 (0)