diff options
-rw-r--r-- | ranger/ext/popen_forked.py | 23 | ||||
-rwxr-xr-x | ranger/ext/rifle.py | 23 |
2 files changed, 22 insertions, 24 deletions
diff --git a/ranger/ext/popen_forked.py b/ranger/ext/popen_forked.py index 0dd52252..10aab83c 100644 --- a/ranger/ext/popen_forked.py +++ b/ranger/ext/popen_forked.py @@ -8,19 +8,16 @@ def Popen_forked(*args, **kwargs): """ Forks process and runs Popen with the given args and kwargs. - If os.fork() is not supported, runs Popen without forking and returns the - process object returned by Popen. - Otherwise, returns None. + Returns True if forking succeeded, otherwise False. """ try: pid = os.fork() - except: - # fall back to not forking if os.fork() is not supported - return subprocess.Popen(*args, **kwargs) - else: - if pid == 0: - os.setsid() - kwargs['stdin'] = open(os.devnull, 'r') - kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w') - subprocess.Popen(*args, **kwargs) - os._exit(0) + except OSError: + return False + if pid == 0: + os.setsid() + kwargs['stdin'] = open(os.devnull, 'r') + kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w') + subprocess.Popen(*args, **kwargs) + os._exit(0) + return True diff --git a/ranger/ext/rifle.py b/ranger/ext/rifle.py index 55a81df0..e0f0eb1b 100755 --- a/ranger/ext/rifle.py +++ b/ranger/ext/rifle.py @@ -72,19 +72,20 @@ try: from ranger.ext.popen_forked import Popen_forked except ImportError: def Popen_forked(*args, **kwargs): - """Forks process and runs Popen with the given args and kwargs.""" + """ + Forks process and runs Popen with the given args and kwargs. + """ try: pid = os.fork() - except: - # fall back to not forking if os.fork() is not supported - return Popen(*args, **kwargs) - else: - if pid == 0: - os.setsid() - kwargs['stdin'] = open(os.devnull, 'r') - kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w') - Popen(*args, **kwargs) - os._exit(0) + except OSError: + return False + if pid == 0: + os.setsid() + kwargs['stdin'] = open(os.devnull, 'r') + kwargs['stdout'] = kwargs['stderr'] = open(os.devnull, 'w') + subprocess.Popen(*args, **kwargs) + os._exit(0) + return True def _is_terminal(): |