@@ -36,7 +36,7 @@ async def execute(
36
36
(int, str, str): (return code, stdout, stderr)
37
37
"""
38
38
39
- def call_subprocess_with_authentication (
39
+ async def call_subprocess_with_authentication (
40
40
cmdline : "List[str]" ,
41
41
username : "str" ,
42
42
password : "str" ,
@@ -45,23 +45,23 @@ def call_subprocess_with_authentication(
45
45
) -> "Tuple[int, str, str]" :
46
46
try :
47
47
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
49
49
)
50
50
51
51
# We expect a prompt from git
52
52
# In most of cases git will prompt for username and
53
53
# then for password
54
54
# In some cases (Bitbucket) username is included in
55
55
# 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 )
57
57
if i == 0 : # ask for username then password
58
58
p .sendline (username )
59
- p .expect ("Password for .*:" )
59
+ await p .expect ("Password for .*:" , async_ = True )
60
60
p .sendline (password )
61
61
elif i == 1 : # only ask for password
62
62
p .sendline (password )
63
63
64
- p .expect (pexpect .EOF )
64
+ await p .expect (pexpect .EOF , async_ = True )
65
65
response = p .before
66
66
67
67
returncode = p .wait ()
@@ -85,18 +85,16 @@ def call_subprocess(
85
85
output , error = process .communicate ()
86
86
return (process .returncode , output .decode ("utf-8" ), error .decode ("utf-8" ))
87
87
88
- current_loop = tornado .ioloop .IOLoop .current ()
89
88
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 (
93
90
cmdline ,
94
91
username ,
95
92
password ,
96
93
cwd ,
97
94
env ,
98
95
)
99
96
else :
97
+ current_loop = tornado .ioloop .IOLoop .current ()
100
98
code , output , error = await current_loop .run_in_executor (
101
99
None , call_subprocess , cmdline , cwd , env
102
100
)
0 commit comments