##// END OF EJS Templates
use Popen instead of getstatusoutput to check for libedit....
MinRK -
Show More
@@ -9,9 +9,13 b' In addition to normal readline stuff, this module provides have_readline'
9 boolean and _outputfile variable used in IPython.utils.
9 boolean and _outputfile variable used in IPython.utils.
10 """
10 """
11
11
12 import re
12 import sys
13 import sys
14 import time
13 import warnings
15 import warnings
14
16
17 from subprocess import Popen, PIPE
18
15 try:
19 try:
16 from readline import *
20 from readline import *
17 import readline as _rl
21 import readline as _rl
@@ -44,24 +48,29 b" if sys.platform == 'win32' and have_readline:"
44 have_readline = False
48 have_readline = False
45
49
46 # Test to see if libedit is being used instead of GNU readline.
50 # Test to see if libedit is being used instead of GNU readline.
47 # Thanks to Boyd Waters for this patch.
51 # Thanks to Boyd Waters for the original patch.
48 uses_libedit = False
52 uses_libedit = False
49 if sys.platform == 'darwin' and have_readline:
53 if sys.platform == 'darwin' and have_readline:
50 import commands
54 # Previously this used commands.getstatusoutput, which uses os.popen.
51 # Boyd's patch had a 'while True' here, I'm always a little worried about
55 # Switching to subprocess.Popen, and exponential falloff for EINTR
52 # infinite loops with such code, so for now I'm taking a more conservative
56 # seems to make this better behaved in environments such as PyQt and gdb
53 # approach. See https://bugs.launchpad.net/ipython/+bug/411599.
57 dt = 1e-3
54 for i in range(10):
58 while dt < 1:
55 try:
59 p = Popen(['otool', '-L', _rl.__file__], stdout=PIPE, stderr=PIPE)
56 (status, result) = commands.getstatusoutput( "otool -L %s | grep libedit" % _rl.__file__ )
60 otool,err = p.communicate()
61
62 if p.returncode == 4:
63 # EINTR
64 time.sleep(dt)
65 dt *= 2
66 continue
67 elif p.returncode:
68 warnings.warn("libedit detection failed: %s"%err)
69 break
70 else:
57 break
71 break
58 except IOError, (errno, strerror):
59 if errno == 4:
60 continue
61 else:
62 break
63
72
64 if status == 0 and len(result) > 0:
73 if p.returncode == 0 and re.search(r'/libedit[\.\d+]*\.dylib\s', otool):
65 # we are bound to libedit - new in Leopard
74 # we are bound to libedit - new in Leopard
66 _rl.parse_and_bind("bind ^I rl_complete")
75 _rl.parse_and_bind("bind ^I rl_complete")
67 warnings.warn("Leopard libedit detected - readline will not be well behaved "
76 warnings.warn("Leopard libedit detected - readline will not be well behaved "
General Comments 0
You need to be logged in to leave comments. Login now