Skip to content

Commit

Permalink
decode subprocess output in launchers
Browse files Browse the repository at this point in the history
  • Loading branch information
minrk committed May 16, 2013
1 parent b7cb333 commit f6657cb
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions IPython/parallel/apps/launcher.py
Expand Up @@ -61,6 +61,7 @@ def check_output(*args, **kwargs):
from IPython.utils.traitlets import (
Any, Integer, CFloat, List, Unicode, Dict, Instance, HasTraits, CRegExp
)
from IPython.utils.encoding import DEFAULT_ENCODING
from IPython.utils.path import get_home_dir
from IPython.utils.process import find_cmd, FindCmdError

Expand All @@ -86,7 +87,6 @@ def check_output(*args, **kwargs):
# Base launchers and errors
#-----------------------------------------------------------------------------


class LauncherError(Exception):
pass

Expand Down Expand Up @@ -613,10 +613,10 @@ def _fetch_file(self, remote, local):
# wait up to 10s for remote file to exist
check = check_output(self.ssh_cmd + self.ssh_args + \
[self.location, 'test -e', remote, "&& echo 'yes' || echo 'no'"])
check = check.strip()
if check == 'no':
check = check.decode(DEFAULT_ENCODING, 'replace').strip()
if check == u'no':
time.sleep(1)
elif check == 'yes':
elif check == u'yes':
break
check_output(self.scp_cmd + [full_remote, local])

Expand Down Expand Up @@ -889,6 +889,7 @@ def start(self, n):
cwd=self.work_dir,
stderr=STDOUT
)
output = output.decode(DEFAULT_ENCODING, 'replace')
job_id = self.parse_job_id(output)
self.notify_start(job_id)
return job_id
Expand All @@ -906,8 +907,9 @@ def stop(self):
cwd=self.work_dir,
stderr=STDOUT
)
output = output.decode(DEFAULT_ENCODING, 'replace')
except:
output = 'The job already appears to be stoppped: %r' % self.job_id
output = u'The job already appears to be stopped: %r' % self.job_id
self.notify_stop(dict(job_id=self.job_id, output=output)) # Pass the output of the kill cmd
return output

Expand Down Expand Up @@ -1117,13 +1119,15 @@ def start(self, n):
# can be used in the batch script template as {profile_dir}
self.write_batch_script(n)
output = check_output(self.args, env=os.environ)
output = output.decode(DEFAULT_ENCODING, 'replace')

job_id = self.parse_job_id(output)
self.notify_start(job_id)
return job_id

def stop(self):
output = check_output(self.delete_command+[self.job_id], env=os.environ)
output = output.decode(DEFAULT_ENCODING, 'replace')
self.notify_stop(dict(job_id=self.job_id, output=output)) # Pass the output of the kill cmd
return output

Expand Down Expand Up @@ -1242,11 +1246,11 @@ def start(self, n):
# Here we save profile_dir in the context so they
# can be used in the batch script template as {profile_dir}
self.write_batch_script(n)
#output = check_output(self.args, env=os.environ)
piped_cmd = self.args[0]+'<\"'+self.args[1]+'\"'
self.log.debug("Starting %s: %s", self.__class__.__name__, piped_cmd)
p = Popen(piped_cmd, shell=True,env=os.environ,stdout=PIPE)
output,err = p.communicate()
output = output.decode(DEFAULT_ENCODING, 'replace')
job_id = self.parse_job_id(output)
self.notify_start(job_id)
return job_id
Expand Down

0 comments on commit f6657cb

Please sign in to comment.