Handle OSError when using subprocess.

This commit is contained in:
Florian Bruhin 2014-11-23 17:56:14 +01:00
parent 8ec42908f1
commit 655115858c
7 changed files with 23 additions and 11 deletions

View File

@ -546,12 +546,16 @@ class Application(QApplication):
log.destroy.debug("args: {}".format(args))
log.destroy.debug("cwd: {}".format(cwd))
# Open a new process and immediately shutdown the existing one
if cwd is None:
subprocess.Popen(args)
try:
if cwd is None:
subprocess.Popen(args)
else:
subprocess.Popen(args, cwd=cwd)
except OSError as e:
log.destroy.error("Failed to restart: {}".format(e))
else:
subprocess.Popen(args, cwd=cwd)
if shutdown:
self.shutdown()
if shutdown:
self.shutdown()
@cmdutils.register(instance='app', split=False, debug=True)
def debug_pyeval(self, s):

View File

@ -794,7 +794,11 @@ class CommandDispatcher:
*args: The commandline to execute.
"""
log.procs.debug("Executing: {}".format(args))
subprocess.Popen(args)
try:
subprocess.Popen(args)
except OSError as e:
raise cmdexc.CommandError("Error while spawning command: "
"{}".format(e))
@cmdutils.register(instance='command-dispatcher', scope='window')
def home(self):

View File

@ -420,7 +420,11 @@ class HintManager(QObject):
"""Spawn a simple command from a hint."""
urlstr = url.toString(QUrl.FullyEncoded | QUrl.RemovePassword)
args = self._context.get_args(urlstr)
subprocess.Popen(args)
try:
subprocess.Popen(args)
except OSError as e:
msg = "Error while spawning command: {}".format(e)
message.error(self._win_id, msg, immediately=True)
def _resolve_url(self, elem, baseurl=None):
"""Resolve a URL and check if we want to keep it.

View File

@ -96,7 +96,7 @@ def _git_str_subprocess(gitpath):
['git', 'show', '-s', '--format=%ci', 'HEAD'],
cwd=gitpath).decode('UTF-8').strip()
return '{} ({})'.format(cid, date)
except (subprocess.CalledProcessError, FileNotFoundError):
except (subprocess.CalledProcessError, OSError):
return None

View File

@ -50,7 +50,7 @@ def call_asciidoc(src, dst):
args.append(src)
try:
subprocess.check_call(args)
except subprocess.CalledProcessError as e:
except (subprocess.CalledProcessError, OSError) as e:
utils.print_col(str(e), 'red')
sys.exit(1)
except FileNotFoundError:

View File

@ -96,7 +96,7 @@ def _run_subprocess(name, args):
"""Run a checker via subprocess."""
try:
return subprocess.call([name] + args)
except FileNotFoundError:
except OSError:
traceback.print_exc()
return None

View File

@ -78,7 +78,7 @@ def _git_str():
['git', 'show', '-s', '--format=%ci', 'HEAD'],
cwd=BASEDIR).decode('UTF-8').strip()
return '{} ({})'.format(cid, date)
except (subprocess.CalledProcessError, FileNotFoundError):
except (subprocess.CalledProcessError, OSError):
return None