@@ -1173,15 +1173,15 @@ async def output(self, podman_args, cmd="", cmd_args=None):
11731173 xargs = self .compose .get_podman_args (cmd ) if cmd else []
11741174 cmd_ls = [self .podman_path , * podman_args , cmd ] + xargs + cmd_args
11751175 log .info (str (cmd_ls ))
1176- p = await asyncio .subprocess . create_subprocess_exec (
1176+ p = await asyncio .create_subprocess_exec (
11771177 * cmd_ls , stdout = asyncio .subprocess .PIPE , stderr = asyncio .subprocess .PIPE
11781178 )
11791179
11801180 stdout_data , stderr_data = await p .communicate ()
11811181 if p .returncode == 0 :
11821182 return stdout_data
1183- else :
1184- raise subprocess .CalledProcessError (p .returncode , " " .join (cmd_ls ), stderr_data )
1183+
1184+ raise subprocess .CalledProcessError (p .returncode , " " .join (cmd_ls ), stderr_data )
11851185
11861186 def exec (
11871187 self ,
@@ -1195,7 +1195,7 @@ def exec(
11951195 log .info (" " .join ([str (i ) for i in cmd_ls ]))
11961196 os .execlp (self .podman_path , * cmd_ls )
11971197
1198- async def run (
1198+ async def run ( # pylint: disable=dangerous-default-value
11991199 self ,
12001200 podman_args ,
12011201 cmd = "" ,
@@ -1223,7 +1223,7 @@ async def format_out(stdout):
12231223 if stdout .at_eof ():
12241224 break
12251225
1226- p = await asyncio .subprocess . create_subprocess_exec (
1226+ p = await asyncio .create_subprocess_exec (
12271227 * cmd_ls , stdout = asyncio .subprocess .PIPE , stderr = asyncio .subprocess .PIPE
12281228 ) # pylint: disable=consider-using-with
12291229
@@ -1238,7 +1238,7 @@ async def format_out(stdout):
12381238 err_t .add_done_callback (task_reference .discard )
12391239
12401240 else :
1241- p = await asyncio .subprocess . create_subprocess_exec (* cmd_ls ) # pylint: disable=consider-using-with
1241+ p = await asyncio .create_subprocess_exec (* cmd_ls ) # pylint: disable=consider-using-with
12421242
12431243 try :
12441244 exit_code = await p .wait ()
@@ -1916,9 +1916,12 @@ def _init_global_parser(parser):
19161916
19171917podman_compose = PodmanCompose ()
19181918
1919+
19191920###################
19201921# decorators to add commands and parse options
19211922###################
1923+ class PodmanComposeError (Exception ):
1924+ pass
19221925
19231926
19241927class cmd_run : # pylint: disable=invalid-name,too-few-public-methods
@@ -1932,7 +1935,7 @@ def wrapped(*args, **kw):
19321935 return func (* args , ** kw )
19331936
19341937 if not asyncio .iscoroutinefunction (func ):
1935- raise Exception ("Command must be async" )
1938+ raise PodmanComposeError ("Command must be async" )
19361939 wrapped ._compose = self .compose
19371940 # Trim extra indentation at start of multiline docstrings.
19381941 wrapped .desc = self .cmd_desc or re .sub (r"^\s+" , "" , func .__doc__ )
@@ -2014,8 +2017,8 @@ async def compose_systemd(compose, args):
20142017 f .write (f"{ k } ={ v } \n " )
20152018 log .debug ("writing [%s]: done." , fn )
20162019 log .info ("\n \n creating the pod without starting it: ...\n \n " )
2017- process = await asyncio .subprocess . create_subprocess_exec (script , ["up" , "--no-start" ])
2018- log .info ("\n final exit code is " , process )
2020+ process = await asyncio .create_subprocess_exec (script , ["up" , "--no-start" ])
2021+ log .info ("\n final exit code is %d " , process )
20192022 username = getpass .getuser ()
20202023 print (
20212024 f"""
@@ -2299,6 +2302,14 @@ async def compose_up(compose: PodmanCompose, args):
22992302 )
23002303 )
23012304
2305+ def _task_cancelled (task : Task ) -> bool :
2306+ if task .cancelled ():
2307+ return True
2308+ # Task.cancelling() is new in python 3.11
2309+ if sys .version_info >= (3 , 11 ) and task .cancelling ():
2310+ return True
2311+ return False
2312+
23022313 exit_code = 0
23032314 exiting = False
23042315 while tasks :
@@ -2309,7 +2320,9 @@ async def compose_up(compose: PodmanCompose, args):
23092320 # cause the status to overwrite. Sleeping for 1 seems to fix this and make it match
23102321 # docker-compose
23112322 await asyncio .sleep (1 )
2312- [_ .cancel () for _ in tasks if not _ .cancelling () and not _ .cancelled ()]
2323+ for t in tasks :
2324+ if not _task_cancelled (t ):
2325+ t .cancel ()
23132326 t : Task
23142327 exiting = True
23152328 for t in done :
0 commit comments