From c411cc843c6cb70620b16cbaf12a5a0610f27f21 Mon Sep 17 00:00:00 2001 From: Rodrigue Cloutier Date: Thu, 10 Dec 2015 10:22:06 -0500 Subject: Fix Windows support for multiprocessing monkey patch --HG-- branch : windows_multiprocessing_support --- coverage/monkey.py | 42 ++++++++++++++++++++++-------------------- igor.py | 7 ++++++- tests/test_concurrency.py | 4 ---- 3 files changed, 28 insertions(+), 25 deletions(-) diff --git a/coverage/monkey.py b/coverage/monkey.py index c4ec68c6..b896dbf5 100644 --- a/coverage/monkey.py +++ b/coverage/monkey.py @@ -11,6 +11,28 @@ import sys # monkey-patched. PATCHED_MARKER = "_coverage$patched" +if sys.version_info >= (3, 4): + + klass = multiprocessing.process.BaseProcess +else: + klass = multiprocessing.Process + +original_bootstrap = klass._bootstrap + + +class ProcessWithCoverage(klass): + """A replacement for multiprocess.Process that starts coverage.""" + def _bootstrap(self): + """Wrapper around _bootstrap to start coverage.""" + from coverage import Coverage + cov = Coverage(data_suffix=True) + cov.start() + try: + return original_bootstrap(self) + finally: + cov.stop() + cov.save() + def patch_multiprocessing(): """Monkey-patch the multiprocessing module. @@ -22,26 +44,6 @@ def patch_multiprocessing(): if hasattr(multiprocessing, PATCHED_MARKER): return - if sys.version_info >= (3, 4): - klass = multiprocessing.process.BaseProcess - else: - klass = multiprocessing.Process - - original_bootstrap = klass._bootstrap - - class ProcessWithCoverage(klass): - """A replacement for multiprocess.Process that starts coverage.""" - def _bootstrap(self): - """Wrapper around _bootstrap to start coverage.""" - from coverage import Coverage - cov = Coverage(data_suffix=True) - cov.start() - try: - return original_bootstrap(self) - finally: - cov.stop() - cov.save() - if sys.version_info >= (3, 4): klass._bootstrap = ProcessWithCoverage._bootstrap else: diff --git a/igor.py b/igor.py index 409fdc91..b857fcc3 100644 --- a/igor.py +++ b/igor.py @@ -328,7 +328,12 @@ def print_banner(label): if '__pypy__' in sys.builtin_module_names: version += " (pypy %s)" % ".".join(str(v) for v in sys.pypy_version_info) - which_python = os.path.relpath(sys.executable) + try: + which_python = os.path.relpath(sys.executable) + except ValueError: + # On Windows having a python executable on a different drives + # than the sources cannot be relative + which_python = sys.executable print('=== %s %s %s (%s) ===' % (impl, version, label, which_python)) sys.stdout.flush() diff --git a/tests/test_concurrency.py b/tests/test_concurrency.py index c6d750d0..97aa55ff 100644 --- a/tests/test_concurrency.py +++ b/tests/test_concurrency.py @@ -224,10 +224,6 @@ class MultiprocessingTest(CoverageTest): def setUp(self): super(MultiprocessingTest, self).setUp() - # Currently, this doesn't work on Windows, something about pickling - # the monkey-patched Process class? - if env.WINDOWS: - self.skip("Multiprocessing support doesn't work on Windows") def test_multiprocessing(self): self.make_file("multi.py", """\ -- cgit v1.2.1