def _init_for_start(self): """Initialization for start()""" # Construct the collector. concurrency = self.config.concurrency or [] if "multiprocessing" in concurrency: if not patch_multiprocessing: raise CoverageException( # pragma: only jython "multiprocessing is not supported on this Python" ) patch_multiprocessing(rcfile=self.config.config_file) # Multi-processing uses parallel for the subprocesses, so also use # it for the main process. self.config.parallel = True if self.config.dynamic_context is None: context_switchers = [] elif self.config.dynamic_context == "test_function": context_switchers = [should_start_context_test_function] else: raise CoverageException( "Don't understand dynamic_context setting: {!r}".format(self.config.dynamic_context) ) context_switchers.extend( plugin.dynamic_context for plugin in self._plugins.context_switchers ) should_start_context = combine_context_switchers(context_switchers) self._collector = Collector( should_trace=self._should_trace, check_include=self._check_include_omit_etc, should_start_context=should_start_context, timid=self.config.timid, branch=self.config.branch, warn=self._warn, concurrency=concurrency, ) suffix = self._data_suffix_specified if suffix or self.config.parallel: if not isinstance(suffix, string_class): # if data_suffix=True, use .machinename.pid.random suffix = True else: suffix = None self._init_data(suffix) self._collector.use_data(self._data, self.config.context) # Early warning if we aren't going to be able to support plugins. if self._plugins.file_tracers and not self._collector.supports_plugins: self._warn( "Plugin file tracers (%s) aren't supported with %s" % ( ", ".join( plugin._coverage_plugin_name for plugin in self._plugins.file_tracers ), self._collector.tracer_name(), ) ) for plugin in self._plugins.file_tracers: plugin._coverage_enabled = False # Create the file classifying substructure. self._inorout = self._inorout_class(warn=self._warn) self._inorout.configure(self.config) self._inorout.plugins = self._plugins self._inorout.disp_class = self._collector.file_disposition_class atexit.register(self._atexit)
def _init_for_start(self): """Initialization for start()""" # Construct the collector. concurrency = self.config.concurrency or () if "multiprocessing" in concurrency: if not patch_multiprocessing: raise CoverageException( # pragma: only jython "multiprocessing is not supported on this Python" ) patch_multiprocessing(rcfile=self.config.config_file) dycon = self.config.dynamic_context if not dycon or dycon == "none": context_switchers = [] elif dycon == "test_function": context_switchers = [should_start_context_test_function] else: raise CoverageException( "Don't understand dynamic_context setting: {!r}".format(dycon) ) context_switchers.extend( plugin.dynamic_context for plugin in self._plugins.context_switchers ) should_start_context = combine_context_switchers(context_switchers) self._collector = Collector( should_trace=self._should_trace, check_include=self._check_include_omit_etc, should_start_context=should_start_context, file_mapper=self._file_mapper, timid=self.config.timid, branch=self.config.branch, warn=self._warn, concurrency=concurrency, ) suffix = self._data_suffix_specified if suffix or self.config.parallel: if not isinstance(suffix, string_class): # if data_suffix=True, use .machinename.pid.random suffix = True else: suffix = None self._init_data(suffix) self._collector.use_data(self._data, self.config.context) # Early warning if we aren't going to be able to support plugins. if self._plugins.file_tracers and not self._collector.supports_plugins: self._warn( "Plugin file tracers (%s) aren't supported with %s" % ( ", ".join( plugin._coverage_plugin_name for plugin in self._plugins.file_tracers ), self._collector.tracer_name(), ) ) for plugin in self._plugins.file_tracers: plugin._coverage_enabled = False # Create the file classifying substructure. self._inorout = self._inorout_class(warn=self._warn) self._inorout.configure(self.config) self._inorout.plugins = self._plugins self._inorout.disp_class = self._collector.file_disposition_class # It's useful to write debug info after initing for start. self._should_write_debug = True atexit.register(self._atexit)
def _init_for_start(self): """Initialization for start()""" # Construct the collector. concurrency = self.config.concurrency or [] if "multiprocessing" in concurrency: if not patch_multiprocessing: raise ConfigError( # pragma: only jython "multiprocessing is not supported on this Python") if self.config.config_file is None: raise ConfigError( "multiprocessing requires a configuration file") patch_multiprocessing(rcfile=self.config.config_file) dycon = self.config.dynamic_context if not dycon or dycon == "none": context_switchers = [] elif dycon == "test_function": context_switchers = [should_start_context_test_function] else: raise ConfigError( f"Don't understand dynamic_context setting: {dycon!r}") context_switchers.extend(plugin.dynamic_context for plugin in self._plugins.context_switchers) should_start_context = combine_context_switchers(context_switchers) self._collector = Collector( should_trace=self._should_trace, check_include=self._check_include_omit_etc, should_start_context=should_start_context, file_mapper=self._file_mapper, timid=self.config.timid, branch=self.config.branch, warn=self._warn, concurrency=concurrency, ) suffix = self._data_suffix_specified if suffix: if not isinstance(suffix, str): # if data_suffix=True, use .machinename.pid.random suffix = True elif self.config.parallel: if suffix is None: suffix = True elif not isinstance(suffix, str): suffix = bool(suffix) else: suffix = None self._init_data(suffix) self._collector.use_data(self._data, self.config.context) # Early warning if we aren't going to be able to support plugins. if self._plugins.file_tracers and not self._collector.supports_plugins: self._warn( "Plugin file tracers ({}) aren't supported with {}".format( ", ".join(plugin._coverage_plugin_name for plugin in self._plugins.file_tracers), self._collector.tracer_name(), )) for plugin in self._plugins.file_tracers: plugin._coverage_enabled = False # Create the file classifying substructure. self._inorout = InOrOut( warn=self._warn, debug=(self._debug if self._debug.should('trace') else None), ) self._inorout.configure(self.config) self._inorout.plugins = self._plugins self._inorout.disp_class = self._collector.file_disposition_class # It's useful to write debug info after initing for start. self._should_write_debug = True # Register our clean-up handlers. atexit.register(self._atexit) is_main = (threading.current_thread() == threading.main_thread()) if is_main and not env.WINDOWS: # The Python docs seem to imply that SIGTERM works uniformly even # on Windows, but that's not my experience, and this agrees: # https://stackoverflow.com/questions/35772001/x/35792192#35792192 self._old_sigterm = signal.signal(signal.SIGTERM, self._on_sigterm)