eric6/DebugClients/Python/coverage/multiproc.py

changeset 7427
362cd1b6f81a
parent 7275
9a25fe1fab84
child 7702
f8b97639deb5
--- a/eric6/DebugClients/Python/coverage/multiproc.py	Wed Feb 19 19:38:36 2020 +0100
+++ b/eric6/DebugClients/Python/coverage/multiproc.py	Sat Feb 22 14:27:42 2020 +0100
@@ -1,43 +1,49 @@
 # Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://bitbucket.org/ned/coveragepy/src/default/NOTICE.txt
+# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
 
 """Monkey-patching to add multiprocessing support for coverage.py"""
 
 import multiprocessing
 import multiprocessing.process
 import os
+import os.path
 import sys
+import traceback
 
+from coverage import env
 from coverage.misc import contract
 
 # An attribute that will be set on the module to indicate that it has been
 # monkey-patched.
 PATCHED_MARKER = "_coverage$patched"
 
-# The environment variable that specifies the rcfile for subprocesses.
-COVERAGE_RCFILE_ENV = "_COVERAGE_RCFILE"
 
-
-if sys.version_info >= (3, 4):
+if env.PYVERSION >= (3, 4):
     OriginalProcess = multiprocessing.process.BaseProcess
 else:
     OriginalProcess = multiprocessing.Process
 
 original_bootstrap = OriginalProcess._bootstrap
 
-class ProcessWithCoverage(OriginalProcess):
+class ProcessWithCoverage(OriginalProcess):         # pylint: disable=abstract-method
     """A replacement for multiprocess.Process that starts coverage."""
 
     def _bootstrap(self, *args, **kwargs):          # pylint: disable=arguments-differ
         """Wrapper around _bootstrap to start coverage."""
-        from coverage import Coverage       # avoid circular import
-        rcfile = os.environ[COVERAGE_RCFILE_ENV]
-        cov = Coverage(data_suffix=True, config_file=rcfile)
-        cov.start()
-        debug = cov.debug
         try:
+            from coverage import Coverage       # avoid circular import
+            cov = Coverage(data_suffix=True)
+            cov._warn_preimported_source = False
+            cov.start()
+            debug = cov._debug
             if debug.should("multiproc"):
                 debug.write("Calling multiprocessing bootstrap")
+        except Exception:
+            print("Exception during multiprocessing bootstrap init:")
+            traceback.print_exc(file=sys.stdout)
+            sys.stdout.flush()
+            raise
+        try:
             return original_bootstrap(self, *args, **kwargs)
         finally:
             if debug.should("multiproc"):
@@ -73,14 +79,14 @@
     if hasattr(multiprocessing, PATCHED_MARKER):
         return
 
-    if sys.version_info >= (3, 4):
+    if env.PYVERSION >= (3, 4):
         OriginalProcess._bootstrap = ProcessWithCoverage._bootstrap
     else:
         multiprocessing.Process = ProcessWithCoverage
 
     # Set the value in ProcessWithCoverage that will be pickled into the child
     # process.
-    os.environ[COVERAGE_RCFILE_ENV] = rcfile
+    os.environ["COVERAGE_RCFILE"] = os.path.abspath(rcfile)
 
     # When spawning processes rather than forking them, we have no state in the
     # new process.  We sneak in there with a Stowaway: we stuff one of our own

eric ide

mercurial