Skip to content
This repository

skip find_cmd when setting up script magics #2424

Merged
merged 2 commits into from almost 2 years ago

4 participants

Min RK Fernando Perez Jason Grout Matthias Bussonnier
Min RK
Owner

find_cmd was slowing down process startup, and probably unnecessary anyway.

minrk added some commits
Min RK minrk skip find_cmd when setting up script magics
find_cmd was slow, and probably unnecessary anyway.
40041f6
Min RK minrk better message on script magic not found
More relevant now that we register default script magics that probably don't exist.
0556f3b
Fernando Perez
Owner

@jasongrout, would you mind giving this PR a quick test? It would be good to know if it improves your startup situation in any significant way...

Jason Grout

It does seem to make a difference. Thanks!

Jason Grout

to be precise, it cuts our startup time in about 1/2.

Matthias Bussonnier
Collaborator

As it seem to do it's job, and speed up startup a lot, i'm going to merge this guy.

Matthias Bussonnier Carreau merged commit cfe1161 into from
Min RK minrk deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Sep 23, 2012
Min RK minrk skip find_cmd when setting up script magics
find_cmd was slow, and probably unnecessary anyway.
40041f6
Min RK minrk better message on script magic not found
More relevant now that we register default script magics that probably don't exist.
0556f3b
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 20 additions and 25 deletions. Show diff stats Hide diff stats

  1. +20 25 IPython/core/magics/script.py
45 IPython/core/magics/script.py
@@ -12,6 +12,7 @@
12 12 #-----------------------------------------------------------------------------
13 13
14 14 # Stdlib
  15 +import errno
15 16 import os
16 17 import re
17 18 import sys
@@ -30,7 +31,7 @@
30 31 from IPython.lib.backgroundjobs import BackgroundJobManager
31 32 from IPython.testing.skipdoctest import skip_doctest
32 33 from IPython.utils import py3compat
33   -from IPython.utils.process import find_cmd, FindCmdError, arg_split
  34 +from IPython.utils.process import arg_split
34 35 from IPython.utils.traitlets import List, Dict
35 36
36 37 #-----------------------------------------------------------------------------
@@ -90,36 +91,23 @@ class ScriptMagics(Magics, Configurable):
90 91 """,
91 92 )
92 93 def _script_magics_default(self):
93   - """default to a common list of programs if we find them"""
  94 + """default to a common list of programs"""
94 95
95   - defaults = []
96   - to_try = []
97   - if os.name == 'nt':
98   - defaults.append('cmd')
99   - to_try.append('powershell')
100   - to_try.extend([
  96 + defaults = [
101 97 'sh',
102 98 'bash',
103 99 'perl',
104 100 'ruby',
  101 + 'python',
105 102 'python3',
106 103 'pypy',
107   - ])
  104 + ]
  105 + if os.name == 'nt':
  106 + defaults.extend([
  107 + 'cmd',
  108 + 'powershell',
  109 + ])
108 110
109   - for cmd in to_try:
110   - if cmd in self.script_paths:
111   - defaults.append(cmd)
112   - else:
113   - try:
114   - find_cmd(cmd)
115   - except FindCmdError:
116   - # command not found, ignore it
117   - pass
118   - except ImportError:
119   - # Windows without pywin32, find_cmd doesn't work
120   - pass
121   - else:
122   - defaults.append(cmd)
123 111 return defaults
124 112
125 113 script_paths = Dict(config=True,
@@ -197,8 +185,15 @@ def shebang(self, line, cell):
197 185 """
198 186 argv = arg_split(line, posix = not sys.platform.startswith('win'))
199 187 args, cmd = self.shebang.parser.parse_known_args(argv)
200   -
201   - p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
  188 +
  189 + try:
  190 + p = Popen(cmd, stdout=PIPE, stderr=PIPE, stdin=PIPE)
  191 + except OSError as e:
  192 + if e.errno == errno.ENOENT:
  193 + print "Couldn't find program: %r" % cmd[0]
  194 + return
  195 + else:
  196 + raise
202 197
203 198 cell = cell.encode('utf8', 'replace')
204 199 if args.bg:

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.