Skip to content

Commit

Permalink
Improve clean-all/kill-pantsd. Rename process lock.
Browse files Browse the repository at this point in the history
  • Loading branch information
kwlzn committed Mar 26, 2018
1 parent 3d92138 commit 59cbe63
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/python/pants/core_tasks/pantsd_kill.py
Expand Up @@ -16,6 +16,6 @@ class PantsDaemonKill(Task):

def execute(self):
try:
PantsDaemon.Factory.create(self.context.options).terminate()
PantsDaemon.Factory.create(self.context.options, full_init=False).terminate()
except ProcessManager.NonResponsiveProcess as e:
raise TaskError('failure while terminating pantsd: {}'.format(e))
20 changes: 11 additions & 9 deletions src/python/pants/pantsd/pants_daemon.py
Expand Up @@ -80,9 +80,11 @@ def maybe_launch(cls, bootstrap_options=None):
"""Creates and launches a daemon instance if one does not already exist.
:param Options bootstrap_options: The bootstrap options, if available.
:returns: The pailgun port number of the running pantsd instance.
:rtype: int
"""
stub_pantsd = cls.create(bootstrap_options, full_init=False)
with stub_pantsd.process_lock:
with stub_pantsd.lifecycle_lock:
if stub_pantsd.needs_restart(stub_pantsd.options_fingerprint):
# Once we determine we actually need to launch, recreate with full initialization.
pantsd = cls.create(bootstrap_options)
Expand All @@ -99,17 +101,16 @@ def create(cls, bootstrap_options=None, full_init=True):
bootstrap_options = bootstrap_options or cls._parse_bootstrap_options()
bootstrap_options_values = bootstrap_options.for_global_scope()

# TODO: https://github.com/pantsbuild/pants/issues/3479
watchman = WatchmanLauncher.create(bootstrap_options_values).watchman
native = None
build_root = None
watchman = None
services = None
port_map = None

if full_init:
build_root = get_buildroot()
native = Native.create(bootstrap_options_values)
# TODO: https://github.com/pantsbuild/pants/issues/3479
watchman = WatchmanLauncher.create(bootstrap_options_values).watchman
legacy_graph_helper = cls._setup_legacy_graph_helper(native, bootstrap_options_values)
services, port_map = cls._setup_services(
build_root,
Expand Down Expand Up @@ -363,7 +364,7 @@ def post_fork_child(self):
def needs_launch(self):
"""Determines if pantsd needs to be launched.
N.B. This should always be called under care of `self.process_lock`.
N.B. This should always be called under care of `self.lifecycle_lock`.
:returns: True if the daemon needs launching, False otherwise.
:rtype: bool
Expand All @@ -376,7 +377,7 @@ def needs_launch(self):
def launch(self):
"""Launches pantsd in a subprocess.
N.B. This should always be called under care of `self.process_lock`.
N.B. This should always be called under care of `self.lifecycle_lock`.
:returns: The port that pantsd is listening on.
:rtype: int
Expand All @@ -394,9 +395,10 @@ def launch(self):

def terminate(self, include_watchman=True):
"""Terminates pantsd and watchman."""
super(PantsDaemon, self).terminate()
if include_watchman:
self.watchman_launcher.terminate()
with self.lifecycle_lock:
super(PantsDaemon, self).terminate()
if include_watchman:
self.watchman_launcher.terminate()


def launch():
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/pantsd/process_manager.py
Expand Up @@ -257,7 +257,7 @@ def process_name(self):
return self._process_name

@memoized_property
def process_lock(self):
def lifecycle_lock(self):
"""An identity-keyed inter-process lock for safeguarding lifecycle and other operations."""
safe_mkdir(self._metadata_base_dir)
return OwnerPrintingInterProcessFileLock(
Expand Down

0 comments on commit 59cbe63

Please sign in to comment.