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