Skip to content

Commit

Permalink
pylint version
Browse files Browse the repository at this point in the history
  • Loading branch information
dciangot authored Sep 6, 2021
1 parent 267c293 commit ca78a59
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ __pycache__/
.pytest_cache
*~
.vscode
.venv
39 changes: 21 additions & 18 deletions remote_slurm_spawner/remote_slurm_spawner.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ async def submit_batch_script(self):
except:
self.log.error("Job submission failed with exit code " + out)
self.job_id = ""
return self.job_id
return

# Override if your batch system needs something more elaborate to query the job status
batch_query_cmd = Unicode(
Expand Down Expand Up @@ -333,7 +333,7 @@ async def query_job_status(self):
except RuntimeError as e:
# e.args[0] is stderr from the process
self.job_status = e.args[0]
except Exception as e:
except:
self.log.error("Error querying job " + self.job_id)
self.job_status = ""

Expand Down Expand Up @@ -426,7 +426,7 @@ async def start(self):
if jupyterhub.version_info >= (0, 8) and self.server:
self.server.port = self.port

job = await self.submit_batch_script()
await self.submit_batch_script()

# We are called with a timeout, and if the timeout expires this function will
# be interrupted at the next yield, and self.stop() will be called.
Expand Down Expand Up @@ -491,7 +491,7 @@ async def stop(self, now=False):
await self.cancel_batch_job()
if now:
return
for i in range(10):
for _ in range(10):
status = await self.query_job_status()
if status not in (JobStatus.RUNNING, JobStatus.UNKNOWN):
return
Expand Down Expand Up @@ -742,7 +742,9 @@ async def start(self):
if jupyterhub.version_info >= (0,8) and self.server:
self.server.port = self.port

job = await self.submit_batch_script()
await self.submit_batch_script()

subvars = self.get_req_subvars()

# We are called with a timeout, and if the timeout expires this function will
# be interrupted at the next yield, and self.stop() will be called.
Expand Down Expand Up @@ -778,11 +780,11 @@ async def start(self):

try:
cmd = 'nohup sshpass -f %s ssh -n -f %s@%s -L %s:%s:%s -M -S %s/tunnel-%s -fN machine-%s &' \
% (self.sshPwdFile,
self.sshUser,
self.sshHost,
% (subvars["sshPwdFile"],
subvars["sshUser"],
subvars["sshHost"],
self.port, self.ip, self.port,
self.sshTunnelsFolder,
subvars["sshTunnelsFolder"],
self.port, self.port)
self.log.info('Tunneling ' + self.ip + ":" + str(self.port) + ' via localhost:' + str(self.port))
self.log.debug('Executing command: %s', cmd)
Expand Down Expand Up @@ -812,9 +814,10 @@ async def stop(self, now=False):
Returns immediately after sending job cancellation command if now=True, otherwise
tries to confirm that job is no longer running."""

subvars = self.get_req_subvars()
self.log.info("Stopping ssh tunnel on port: " + self.port)
try:
cmd = "ssh -S %s/tunnel-%s -O exit machine-%s" % (self.sshTunnelsFolder, self.port, self.port)
cmd = "ssh -S %s/tunnel-%s -O exit machine-%s" % (subvars["sshTunnelsFolder"], self.port, self.port)
self.log.debug('Executing command: %s', cmd)
p = subprocess.Popen(cmd, shell=True)
outs, errs = p.communicate(timeout=15)
Expand All @@ -827,7 +830,7 @@ async def stop(self, now=False):
await self.cancel_batch_job()
if now:
return
for i in range(10):
for _ in range(10):
status = await self.query_job_status()
if status not in (JobStatus.RUNNING, JobStatus.UNKNOWN):
return
Expand Down Expand Up @@ -855,14 +858,14 @@ async def submit_batch_script(self):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

with open(self.sshPwdFile) as f:
ssh.connect(self.sshHost, username=self.sshUser, password=f.read())
with open(subvars["sshPwdFile"]) as f:
ssh.connect(subvars["sshHost"], username=subvars["sshUser"], password=f.read())
env_string = ""
for k,v in self.get_env().items():
if "JUPYTERHUB" in k:
env_string += "export %s=%s \n" % (k,v)
self.log.info(env_string)
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command('echo "%s" | ' % script.replace("__export__", env_string) + cmd )
_, ssh_stdout, ssh_stderr = ssh.exec_command('echo "%s" | ' % script.replace("__export__", env_string) + cmd )
out = str(ssh_stdout.read())
self.log.info(str(ssh_stderr.read()))
self.log.info(self.get_env())
Expand Down Expand Up @@ -900,16 +903,16 @@ async def query_job_status(self):
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

with open(self.sshPwdFile) as f:
ssh.connect(self.sshHost, username=self.sshUser, password=f.read())
ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command( cmd )
with open(subvars["sshPwdFile"]) as f:
ssh.connect(subvars["sshHost"], username=subvars["sshUser"], password=f.read())
_, ssh_stdout, ssh_stderr = ssh.exec_command( cmd )
out = str(ssh_stdout.readlines())
self.log.info(str(ssh_stderr.readlines()))
self.log.info(out)
out = out.replace("[","").replace("'","").split(" n")[0].split("\\n")[0]
ssh.close()
self.job_status = out
except Exception as e:
except:
self.log.error('Error querying job ' + self.job_id)
self.job_status = ''

Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
version_info = (
0,
1,
1,
2,
"dev", # comment-out this line for a release
)
__version__ = ".".join(map(str, version_info))

0 comments on commit ca78a59

Please sign in to comment.