summaryrefslogtreecommitdiff
path: root/src/flake8
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-10-28 09:17:59 -0700
committerAnthony Sottile <asottile@umich.edu>2019-10-28 09:43:30 -0700
commit51f32bbe93497143b204b95b7ca5513e61754fef (patch)
treeffa70a83a56af9aeb0dd5a5e124f239e868731b3 /src/flake8
parentd599950e6ee19ecf0a05e527cd1381ce71182a24 (diff)
downloadflake8-51f32bbe93497143b204b95b7ca5513e61754fef.tar.gz
Only use multiprocessing when the method is fork
In python3.8 on macos and in all versions on windows the multiprocessing method is `spawn` which does not preserve class state.
Diffstat (limited to 'src/flake8')
-rw-r--r--src/flake8/checker.py28
-rw-r--r--src/flake8/utils.py24
2 files changed, 14 insertions, 38 deletions
diff --git a/src/flake8/checker.py b/src/flake8/checker.py
index 59064d9..a454f2f 100644
--- a/src/flake8/checker.py
+++ b/src/flake8/checker.py
@@ -4,6 +4,7 @@ import errno
import itertools
import logging
import signal
+import sys
import tokenize
from typing import Dict, List, Optional, Tuple
@@ -35,6 +36,18 @@ SERIAL_RETRY_ERRNOS = {
}
+def _multiprocessing_is_fork(): # type () -> bool
+ """Class state is only preserved when using the `fork` strategy."""
+ if sys.version_info >= (3, 4):
+ return (
+ multiprocessing
+ # https://github.com/python/typeshed/pull/3415
+ and multiprocessing.get_start_method() == "fork" # type: ignore
+ )
+ else:
+ return multiprocessing and not utils.is_windows()
+
+
class Manager(object):
"""Manage the parallelism and checker instances for each plugin and file.
@@ -101,26 +114,13 @@ class Manager(object):
# - we're processing a diff, which again does not work well with
# multiprocessing and which really shouldn't require multiprocessing
# - the user provided some awful input
- if not multiprocessing:
+ if not _multiprocessing_is_fork():
LOG.warning(
"The multiprocessing module is not available. "
"Ignoring --jobs arguments."
)
return 0
- if (
- utils.is_windows()
- and not utils.can_run_multiprocessing_on_windows()
- ):
- LOG.warning(
- "The --jobs option is not available on Windows due to"
- " a bug (https://bugs.python.org/issue27649) in "
- "Python 2.7.11+ and 3.3+. We have detected that you "
- "are running an unsupported version of Python on "
- "Windows. Ignoring --jobs arguments."
- )
- return 0
-
if utils.is_using_stdin(self.arguments):
LOG.warning(
"The --jobs option is not compatible with supplying "
diff --git a/src/flake8/utils.py b/src/flake8/utils.py
index 68eff98..5c7232c 100644
--- a/src/flake8/utils.py
+++ b/src/flake8/utils.py
@@ -298,30 +298,6 @@ def is_windows():
return os.name == "nt"
-# NOTE(sigmavirus24): If and when https://bugs.python.org/issue27649 is fixed,
-# re-enable multiprocessing support on Windows.
-def can_run_multiprocessing_on_windows():
- # type: () -> bool
- """Determine if we can use multiprocessing on Windows.
-
- This presently will **always** return False due to a `bug`_ in the
- :mod:`multiprocessing` module on Windows. Once fixed, we will check
- to ensure that the version of Python contains that fix (via version
- inspection) and *conditionally* re-enable support on Windows.
-
- .. _bug:
- https://bugs.python.org/issue27649
-
- :returns:
- True if the version of Python is modern enough, otherwise False
- :rtype:
- bool
- """
- is_new_enough_python27 = (2, 7, 11) <= sys.version_info < (3, 0)
- is_new_enough_python3 = sys.version_info > (3, 2)
- return False and (is_new_enough_python27 or is_new_enough_python3)
-
-
def is_using_stdin(paths):
# type: (List[str]) -> bool
"""Determine if we're going to read from stdin.