Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8e55af7

Browse files
committed
IPython/utils/_process_posix.py: import pexpect only when needed
1 parent 112e596 commit 8e55af7

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

IPython/utils/_process_posix.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import subprocess as sp
2121
import sys
2222

23-
import pexpect
24-
2523
# Our own
2624
from ._process_common import getoutput, arg_split
2725
from IPython.utils.encoding import DEFAULT_ENCODING
@@ -51,6 +49,7 @@ class ProcessHandler(object):
5149
@property
5250
def sh(self):
5351
if self._sh is None:
52+
import pexpect
5453
shell_name = os.environ.get("SHELL", "sh")
5554
self._sh = pexpect.which(shell_name)
5655
if self._sh is None:
@@ -83,6 +82,7 @@ def getoutput(self, cmd):
8382
file descriptors (so the order of the information in this string is the
8483
correct order as would be seen if running the command in a terminal).
8584
"""
85+
import pexpect
8686
try:
8787
return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
8888
except KeyboardInterrupt:
@@ -104,6 +104,7 @@ def getoutput_pexpect(self, cmd):
104104
file descriptors (so the order of the information in this string is the
105105
correct order as would be seen if running the command in a terminal).
106106
"""
107+
import pexpect
107108
try:
108109
return pexpect.run(self.sh, args=['-c', cmd]).replace('\r\n', '\n')
109110
except KeyboardInterrupt:
@@ -121,6 +122,8 @@ def system(self, cmd):
121122
-------
122123
int : child's exitstatus
123124
"""
125+
import pexpect
126+
124127
# Get likely encoding for the output.
125128
enc = DEFAULT_ENCODING
126129

0 commit comments

Comments
 (0)