From ceaa52cb56e1b131d659b95cdbebb5cb63f0d950 2012-04-25 11:29:12 From: Takafumi Arakaki Date: 2012-04-25 11:29:12 Subject: [PATCH] Add `wait` optional argument to `hooks.editor` subprocess.Popen is used instead of os.system in order to spawn editor process in non-blocking manner. --- diff --git a/IPython/core/hooks.py b/IPython/core/hooks.py index 11ca972..29028d7 100644 --- a/IPython/core/hooks.py +++ b/IPython/core/hooks.py @@ -42,6 +42,7 @@ somewhere in your configuration files or ipython command line. #***************************************************************************** import os, bisect +import subprocess import sys from IPython.core.error import TryNext @@ -54,7 +55,7 @@ __all__ = ['editor', 'fix_error_editor', 'synchronize_with_editor', 'show_in_pager','pre_prompt_hook', 'pre_run_code_hook', 'clipboard_get'] -def editor(self,filename, linenum=None): +def editor(self, filename, linenum=None, wait=True): """Open the default editor at the given filename and linenumber. This is IPython's default editor hook, you can use it as an example to @@ -76,7 +77,9 @@ def editor(self,filename, linenum=None): editor = '"%s"' % editor # Call the actual editor - if os.system('%s %s %s' % (editor,linemark,filename)) != 0: + proc = subprocess.Popen('%s %s %s' % (editor, linemark, filename), + shell=True) + if wait and proc.wait() != 0: raise TryNext() import tempfile