Skip to content

Commit 6a660fd

Browse files
committed
more launcher coverage
- remove some dead code - ensure to/from_dict test SSH launcher
1 parent 28cb5b9 commit 6a660fd

File tree

4 files changed

+30
-46
lines changed

4 files changed

+30
-46
lines changed

ipyparallel/cluster/launcher.py

Lines changed: 7 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
import logging
1010
import os
1111
import re
12-
import shlex
12+
import shutil
1313
import signal
1414
import stat
1515
import sys
1616
import threading
1717
import time
1818
from signal import SIGINT
1919
from signal import SIGTERM
20-
from subprocess import check_call
2120
from subprocess import check_output
2221
from subprocess import PIPE
2322
from subprocess import Popen
@@ -27,8 +26,6 @@
2726
import psutil
2827
from IPython.utils.path import ensure_dir_exists
2928
from IPython.utils.path import get_home_dir
30-
from IPython.utils.process import find_cmd
31-
from IPython.utils.process import FindCmdError
3229
from IPython.utils.text import EvalFormatter
3330
from ipython_genutils.encoding import DEFAULT_ENCODING
3431
from ipython_genutils.py3compat import iteritems
@@ -994,7 +991,6 @@ def _wait(self):
994991
else:
995992
break
996993
stop_data = dict(exit_code=exit_code, pid=self.pid, identifier=self.identifier)
997-
output = self.get_output()
998994
self.loop.add_callback(lambda: self.notify_stop(stop_data))
999995

1000996
def _start_waiting(self):
@@ -1117,18 +1113,6 @@ def _engine_cmd_default(self):
11171113
# unset some traits we inherit but don't use
11181114
remote_output_file = ""
11191115

1120-
@property
1121-
def engine_count(self):
1122-
"""determine engine count from `engines` dict"""
1123-
count = 0
1124-
for n in itervalues(self.engines):
1125-
if isinstance(n, (tuple, list)):
1126-
n, args = n
1127-
if isinstance(n, dict):
1128-
n = n['n']
1129-
count += n
1130-
return count
1131-
11321116
def get_output(self, remove=True):
11331117
# no-op in EngineSet, EngineLaunchers take care of this
11341118
return ''
@@ -1174,10 +1158,7 @@ def start(self, n):
11741158
else:
11751159
port = None
11761160

1177-
if started_n >= requested_n:
1178-
break
1179-
1180-
for i in range(n):
1161+
for i in range(min(n, requested_n - started_n)):
11811162
if i > 0:
11821163
time.sleep(self.delay)
11831164
# pass all common traits to the launcher
@@ -1245,18 +1226,6 @@ def start(self, n):
12451226
# -----------------------------------------------------------------------------
12461227

12471228

1248-
# This is only used on Windows.
1249-
def find_job_cmd():
1250-
if WINDOWS:
1251-
try:
1252-
return find_cmd('job')
1253-
except (FindCmdError, ImportError):
1254-
# ImportError will be raised if win32api is not installed
1255-
return 'job'
1256-
else:
1257-
return 'job'
1258-
1259-
12601229
class WindowsHPCLauncher(BaseLauncher):
12611230

12621231
job_id_regexp = CRegExp(
@@ -1276,14 +1245,11 @@ class WindowsHPCLauncher(BaseLauncher):
12761245
scheduler = Unicode(
12771246
'', config=True, help="The hostname of the scheduler to submit the job to."
12781247
)
1279-
job_cmd = Unicode(
1280-
find_job_cmd(), config=True, help="The command for submitting jobs."
1281-
)
1248+
job_cmd = Unicode(config=True, help="The command for submitting jobs.")
12821249

1283-
def __init__(self, work_dir=u'.', config=None, **kwargs):
1284-
super(WindowsHPCLauncher, self).__init__(
1285-
work_dir=work_dir, config=config, **kwargs
1286-
)
1250+
@default("job_cmd")
1251+
def _default_job(self):
1252+
return shutil.which("job") or "job"
12871253

12881254
@property
12891255
def job_file(self):
@@ -1412,7 +1378,7 @@ class BatchSystemLauncher(BaseLauncher):
14121378
This class also has the notion of a batch script. The ``batch_template``
14131379
attribute can be set to a string that is a template for the batch script.
14141380
This template is instantiated using string formatting. Thus the template can
1415-
use {n} fot the number of instances. Subclasses can add additional variables
1381+
use {n} for the number of instances. Subclasses can add additional variables
14161382
to the template dict.
14171383
"""
14181384

ipyparallel/tests/test_cluster.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ async def test_cluster_manager():
235235
m.remove_cluster("nosuchcluster")
236236

237237

238-
@pytest.mark.parametrize("engine_launcher_class", _engine_launcher_classes)
239238
async def test_to_from_dict(Cluster, engine_launcher_class):
240239
cluster = Cluster(engine_launcher_class=engine_launcher_class, n=2)
241240
print(cluster.config, cluster.controller_args)

ipyparallel/tests/test_launcher.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"""
66
import logging
77
import os
8+
import sys
89
import time
10+
from subprocess import Popen
911

1012
import pytest
1113
from traitlets.config import Config
@@ -132,3 +134,20 @@ def test_ssh_remote_profile_dir(ssh_launcher, profile_dir):
132134
cfg[launcher.__class__.__name__].remote_profile_dir = "foo"
133135
launcher.update_config(cfg)
134136
assert launcher.remote_profile_dir == "foo"
137+
138+
139+
def test_ssh_waitpid(capsys):
140+
proc = Popen([sys.executable, '-c', 'import time; time.sleep(1)'])
141+
pid = proc.pid
142+
143+
def _wait_one(timeout):
144+
launcher_mod.ssh_waitpid(pid, timeout=timeout)
145+
captured = capsys.readouterr()
146+
return launcher_mod._ssh_outputs(captured.out)
147+
148+
# first run, it's alive
149+
assert _wait_one(timeout=0.1) == {"process_running": "1"}
150+
# second run, process exits
151+
assert _wait_one(timeout=5) == {"process_running": "0", "exit_code": "-1"}
152+
# third run, process has already exited
153+
assert _wait_one(timeout=5) == {"process_running": "0", "exit_code": "-1"}

ipyparallel/tests/test_ssh.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
from traitlets.config import Config
55

66
from .conftest import Cluster as BaseCluster # noqa: F401
7-
from .test_cluster import test_restart_engines
8-
from .test_cluster import test_signal_engines
9-
from .test_cluster import test_start_stop_cluster
10-
from .test_cluster import test_to_from_dict
7+
from .test_cluster import test_restart_engines # noqa: F401
8+
from .test_cluster import test_signal_engines # noqa: F401
9+
from .test_cluster import test_start_stop_cluster # noqa: F401
10+
from .test_cluster import test_to_from_dict # noqa: F401
1111

1212
# import tests that use engine_launcher_class fixture
1313

0 commit comments

Comments
 (0)