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(
501501 try :
502502 # Send input if provided
503503 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+
504516 if timeout :
505517 stdout , stderr = await asyncio .wait_for (
506- process . communicate ( input = stdin_bytes ), timeout = timeout
518+ communicate_with_timeout ( ), timeout = timeout
507519 )
508520 else :
509- stdout , stderr = await process . communicate ( input = stdin_bytes )
521+ stdout , stderr = await communicate_with_timeout ( )
510522
511523 # Close file handle if using file redirection
512524 if isinstance (stdout_handle , IO ):
You can’t perform that action at this time.
0 commit comments