Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wait optional argument to hooks.editor #1657

Merged
merged 1 commit into from May 10, 2012

Conversation

tkf
Copy link
Contributor

@tkf tkf commented Apr 25, 2012

subprocess.Popen is used instead of os.system in order to spawn editor process in non-blocking manner.

See also: #1655

I think there are two ways to improve this patch (as @takluyver suggested):

  1. When wait == False, sleep short time (0.1 sec) right after starting editor process to check if the editor exits with non-zero exit code.
  2. Catch stdout/err when wait == False so that message will not be printed in unexpected way (like after the next In[] prompt). If we add sleep, error message can be printed only when editor exits immediately with an error.

Please tell me if you want to implement these.

subprocess.Popen is used instead of os.system in order to spawn editor
process in non-blocking manner.
@fperez
Copy link
Member

fperez commented May 2, 2012

Thanks for creating this; as I mentioned in #1655 I'm a bit swamped, will get back to all this in a few days.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, now that it's using subprocess, it might be better to make the call with shell=False (i.e. the default). We only used os.system because IPython dates back to before subprocess even existed. But using shell=True is slower (especially on Windows), and in this case we don't really need it, so we might as well update the code to current best practices.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to avoid shell=True but I thought IPython allows space in editor config, no? For example, emacsclient -tty. If user want to set a path to editor program containing spaces (especially on Windows), it will be problem because you can't do editor.split(). You can use shlex in stdlib but I think it's too much for this purpose. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point! Let's play it safe and keep it as-is then.

@fperez
Copy link
Member

fperez commented May 10, 2012

Looks good, merging now. Thanks!

fperez added a commit that referenced this pull request May 10, 2012
Add `wait` optional argument to `hooks.editor`.  As indicated the discussion for #1655 (superseded by this PR), this allows users to define custom magics that can call editors without waiting for a return value.
@fperez fperez merged commit e881f31 into ipython:master May 10, 2012
mattvonrocketstein pushed a commit to mattvonrocketstein/ipython that referenced this pull request Nov 3, 2014
Add `wait` optional argument to `hooks.editor`.  As indicated the discussion for ipython#1655 (superseded by this PR), this allows users to define custom magics that can call editors without waiting for a return value.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants