File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -501,12 +501,24 @@ async def execute(
501
501
try :
502
502
# Send input if provided
503
503
stdin_bytes = stdin .encode () if stdin else None
504
+
505
+ async def communicate_with_timeout ():
506
+ try :
507
+ return await process .communicate (input = stdin_bytes )
508
+ except Exception as e :
509
+ try :
510
+ process .kill ()
511
+ await process .wait ()
512
+ except Exception :
513
+ pass
514
+ raise e
515
+
504
516
if timeout :
505
517
stdout , stderr = await asyncio .wait_for (
506
- process . communicate ( input = stdin_bytes ), timeout = timeout
518
+ communicate_with_timeout ( ), timeout = timeout
507
519
)
508
520
else :
509
- stdout , stderr = await process . communicate ( input = stdin_bytes )
521
+ stdout , stderr = await communicate_with_timeout ( )
510
522
511
523
# Close file handle if using file redirection
512
524
if isinstance (stdout_handle , IO ):
You can’t perform that action at this time.
0 commit comments