Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pantsd] Clear the global state of subsystems earlier, plus refactorings #8130

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 7 additions & 23 deletions src/python/pants/bin/daemon_pants_runner.py
@@ -1,7 +1,6 @@
# Copyright 2015 Pants project contributors (see CONTRIBUTORS.md).
# Licensed under the Apache License, Version 2.0 (see LICENSE).

import datetime
import os
import sys
import termios
Expand Down Expand Up @@ -115,39 +114,24 @@ def create(cls, sock, args, env, services, scheduler_service):
args=args,
env=env,
services=services,
exit_code=0,
scheduler_service=scheduler_service
)

def __init__(self, maybe_shutdown_socket, args, env, services, exit_code, scheduler_service):
def __init__(self, maybe_shutdown_socket, args, env, services, scheduler_service):
"""
:param socket socket: A connected socket capable of speaking the nailgun protocol.
:param MaybeShutdownSocket maybe_shutdown_socket: A connected socket capable of speaking the nailgun protocol.
:param list args: The arguments (i.e. sys.argv) for this run.
:param dict env: The environment (i.e. os.environ) for this run.
:param LegacyGraphSession graph_helper: The LegacyGraphSession instance to use for BuildGraph
construction. In the event of an exception, this will be
None.
:param TargetRoots target_roots: The `TargetRoots` for this run.
:param PantsServices services: The PantsServices that are currently running.
:param str metadata_base_dir: The ProcessManager metadata_base_dir from options.
:param OptionsBootstrapper options_bootstrapper: An OptionsBootstrapper to reuse.
:param SchedulerService scheduler_service: The SchedulerService that holds the warm graph.
"""
self._name = self._make_identity()
self._maybe_shutdown_socket = maybe_shutdown_socket
self._args = args
self._env = env
self._services = services
self._scheduler_service = scheduler_service

self.exit_code = exit_code

# TODO: this should probably no longer be necesary, remove.
def _make_identity(self):
"""Generate a ProcessManager identity for a given pants run.

This provides for a reasonably unique name e.g. 'pantsd-run-2015-09-16T23_17_56_581899'.
"""
return 'pantsd-run-{}'.format(datetime.datetime.now().strftime('%Y-%m-%dT%H_%M_%S_%f'))
self.exit_code = PANTS_SUCCEEDED_EXIT_CODE

@classmethod
@contextmanager
Expand Down Expand Up @@ -251,13 +235,13 @@ def run(self):
hermetic_environment_as(**self._env), \
encapsulated_global_logger():
try:
# Clean global state.
clean_global_runtime_state(reset_subsystem=True)

options, _, options_bootstrapper = LocalPantsRunner.parse_options(self._args, self._env)
graph_helper, target_roots, exit_code = self._scheduler_service.prepare_v1_graph_run_v2(options, options_bootstrapper)
self.exit_code = exit_code

# Clean global state.
clean_global_runtime_state(reset_subsystem=True)

# Otherwise, conduct a normal run.
with ExceptionSink.exiter_as_until_exception(lambda _: PantsRunFailCheckerExiter()):
runner = LocalPantsRunner.create(
Expand Down