Skip to content

Commit

Permalink
Improve logic
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewrmshin committed Oct 11, 2018
1 parent 4677d67 commit 36bdff5
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 30 deletions.
27 changes: 27 additions & 0 deletions lib/python/rose/popen.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@ def run_bg(self, *args, **kwargs):
raise RosePopenError(args, 1, "", str(exc))
return proc

def run_nohup_gui(self, cmd):
"""Launch+detach a GUI command with nohup.
Launch the GUI command with `nohup bash -c 'exec ...'` redirecting
standard input and outputs from and to `/dev/null`, and setting it to
become a process group leader. Equivalent to a double fork.
Arguments:
cmd (str): command string of the GUI.
Return (subprocess.Popen):
Return the process object for the "nohup" command.
Return None if no DISPLAY is set.
"""
if 'DISPLAY' not in os.environ:
return
return self.run_bg(
r'nohup',
r'bash',
r'-c',
r'exec ' + cmd + r' <"/dev/null" >"/dev/null" 2>&1',
preexec_fn=os.setpgrp,
stdin=open(os.devnull),
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"),
)

def run_ok(self, *args, **kwargs):
"""Same as RosePopener.run, but raise RosePopenError if ret_code != 1.
Expand Down
39 changes: 9 additions & 30 deletions lib/python/rose/suite_engine_procs/cylc.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,39 +132,18 @@ def cmp_suite_conf(

def gcontrol(self, suite_name, args=None):
"""Launch control GUI for a suite_name."""
if 'DISPLAY' not in os.environ:
return
cylc_version = (
self.get_suite_contact(suite_name).get('CYLC_VERSION', ''))
self.popen.run_bg(
r'nohup',
r'bash',
r'-c',
(
r'exec env CYLC_VERSION=%s cylc gui %s %s' +
r' <"/dev/null" >"/dev/null" 2>&1'
) % (cylc_version, suite_name, self.popen.list_to_shell_str(args)),
preexec_fn=os.setpgrp,
stdin=open(os.devnull),
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"),
return self.popen.run_nohup_gui(
r'env CYLC_VERSION=%s cylc gui %s %s' % (
self.get_suite_contact(suite_name).get('CYLC_VERSION', ''),
suite_name,
self.popen.list_to_shell_str(args),
)
)

def gscan(self, args=None):
"""Launch suites scan GUI."""
if 'DISPLAY' not in os.environ:
return
args_str = self.popen.list_to_shell_str(args)
self.popen.run_bg(
r'nohup',
r'bash',
r'-c',
r'exec cylc gscan %s <"/dev/null" >"/dev/null" 2>&1' % (args_str),
preexec_fn=os.setpgrp,
stdin=open(os.devnull),
stdout=open(os.devnull, "wb"),
stderr=open(os.devnull, "wb"),
)
return self.popen.run_nohup_gui(
r'cylc gscan %s' % (self.popen.list_to_shell_str(args),))

def get_running_suites(self):
"""Return a list containing the names of running suites."""
Expand All @@ -173,7 +152,7 @@ def get_running_suites(self):
items = []
for dirpath, dnames, fnames in os.walk(rootd, followlinks=True):
if dirpath != rootd and any(
name in dnames or name in fnames for name in sub_names):
name in dnames + fnames for name in sub_names):
dnames[:] = []
else:
continue
Expand Down

0 comments on commit 36bdff5

Please sign in to comment.