Skip to content

Commit bb70741

Browse files
authored
No timeout and async for pexpect
1 parent e527ae5 commit bb70741

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

jupyterlab_git/git.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async def execute(
3636
(int, str, str): (return code, stdout, stderr)
3737
"""
3838

39-
def call_subprocess_with_authentication(
39+
async def call_subprocess_with_authentication(
4040
cmdline: "List[str]",
4141
username: "str",
4242
password: "str",
@@ -45,23 +45,23 @@ def call_subprocess_with_authentication(
4545
) -> "Tuple[int, str, str]":
4646
try:
4747
p = pexpect.spawn(
48-
cmdline[0], cmdline[1:], cwd=cwd, env=env, encoding="utf-8"
48+
cmdline[0], cmdline[1:], cwd=cwd, env=env, encoding="utf-8", timeout=None
4949
)
5050

5151
# We expect a prompt from git
5252
# In most of cases git will prompt for username and
5353
# then for password
5454
# In some cases (Bitbucket) username is included in
5555
# remote URL, so git will not ask for username
56-
i = p.expect(["Username for .*: ", "Password for .*:"])
56+
i = await p.expect(["Username for .*: ", "Password for .*:"], async_=True)
5757
if i == 0: # ask for username then password
5858
p.sendline(username)
59-
p.expect("Password for .*:")
59+
await p.expect("Password for .*:", async_=True)
6060
p.sendline(password)
6161
elif i == 1: # only ask for password
6262
p.sendline(password)
6363

64-
p.expect(pexpect.EOF)
64+
await p.expect(pexpect.EOF, async_=True)
6565
response = p.before
6666

6767
returncode = p.wait()
@@ -85,18 +85,16 @@ def call_subprocess(
8585
output, error = process.communicate()
8686
return (process.returncode, output.decode("utf-8"), error.decode("utf-8"))
8787

88-
current_loop = tornado.ioloop.IOLoop.current()
8988
if username is not None and password is not None:
90-
code, output, error = await current_loop.run_in_executor(
91-
None,
92-
call_subprocess_with_authentication,
89+
code, output, error = await call_subprocess_with_authentication(
9390
cmdline,
9491
username,
9592
password,
9693
cwd,
9794
env,
9895
)
9996
else:
97+
current_loop = tornado.ioloop.IOLoop.current()
10098
code, output, error = await current_loop.run_in_executor(
10199
None, call_subprocess, cmdline, cwd, env
102100
)

0 commit comments

Comments
 (0)