diff options
author | hut <hut@lavabit.com> | 2012-08-15 01:47:58 +0200 |
---|---|---|
committer | hut <hut@lavabit.com> | 2012-08-15 01:47:58 +0200 |
commit | 413c887bf405265d062516070d6ba3800b1293c0 (patch) | |
tree | 478d55a0cb048f52510fa894f4b9d7573ec642d5 /ranger | |
parent | b2b1c1024a8cff34690e74292b8132b2cf6fa69b (diff) | |
download | ranger-413c887bf405265d062516070d6ba3800b1293c0.tar.gz |
ext.popen_forked: tweak mechanism
Diffstat (limited to 'ranger')
-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(): |