1010from functools import partial
1111from pprint import pformat
1212
13- from . import utils
14-
1513import trio
1614
1715from . import report
16+ from . import utils
1817
1918log = utils .get_logger ()
2019
@@ -26,8 +25,7 @@ class TimeoutError(Exception):
2625
2726
2827class SIPpFailure (RuntimeError ):
29- """SIPp commands failed
30- """
28+ """SIPp commands failed"""
3129
3230
3331class TrioRunner :
@@ -42,13 +40,7 @@ def __init__(
4240 # store proc results
4341 self ._procs = OrderedDict ()
4442
45- async def run (
46- self ,
47- nursery ,
48- cmds ,
49- rate = 300 ,
50- ** kwargs
51- ):
43+ async def run (self , nursery , cmds , rate = 300 , ** kwargs ):
5244 if self .is_alive ():
5345 raise RuntimeError (
5446 "Not all processes from a prior run have completed"
@@ -59,16 +51,15 @@ async def run(
5951 )
6052 # run agent commands in sequence
6153 for cmd in cmds :
62- log .debug (
63- "launching cmd:\n \" {}\" \n " .format (cmd )
64- )
54+ log .debug ('launching cmd:\n "{}"\n ' .format (cmd ))
6555
6656 proc = await nursery .start (
6757 partial (
6858 trio .run_process ,
6959 shlex .split (cmd ),
7060 stdout = subprocess .DEVNULL ,
71- stderr = subprocess .PIPE
61+ stderr = subprocess .PIPE ,
62+ check = False ,
7263 )
7364 )
7465 self ._procs [cmd ] = proc
@@ -125,15 +116,19 @@ async def wait_on_proc(proc):
125116 # all procs were killed by SIGUSR1
126117 raise TimeoutError (
127118 "pids '{}' failed to complete after '{}' seconds" .format (
128- pformat ([p .pid for p in signalled .values ()]), timeout )
119+ pformat ([p .pid for p in signalled .values ()]), timeout
120+ )
129121 )
130122
131123 def iterprocs (self ):
132124 """Iterate all processes which are still alive yielding
133125 (cmd, proc) pairs
134126 """
135- return ((cmd , proc ) for cmd , proc in self ._procs .items ()
136- if proc and proc .poll () is None )
127+ return (
128+ (cmd , proc )
129+ for cmd , proc in self ._procs .items ()
130+ if proc and proc .poll () is None
131+ )
137132
138133 def stop (self ):
139134 """Stop all agents with SIGUSR1 as per SIPp's signal handling"""
@@ -160,8 +155,7 @@ def is_alive(self):
160155 return any (self .iterprocs ())
161156
162157 def clear (self ):
163- """Clear all processes from the last run
164- """
158+ """Clear all processes from the last run"""
165159 assert not self .is_alive (), "Not all processes have completed"
166160 self ._procs .clear ()
167161
@@ -170,28 +164,25 @@ async def run_all_agents(
170164 runner ,
171165 agents ,
172166 timeout = 180 ,
173-
174167) -> TrioRunner :
175- """Run a sequencec of agents using a ``TrioRunner``.
176- """
168+ """Run a sequencec of agents using a ``TrioRunner``."""
169+
177170 async def finalize ():
178171 # this might raise TimeoutError
179172 cmds2procs = await runner .get (timeout = timeout )
180173 agents2procs = list (zip (agents , cmds2procs .values ()))
181174 msg = report .err_summary (agents2procs )
182175 if msg :
183176 # report logs and stderr
184- await report .emit_logfiles (agents2procs )
177+ report .emit_logfiles (agents2procs )
185178 raise SIPpFailure (msg )
186179
187180 return cmds2procs
188181
189182 try :
190183 async with trio .open_nursery () as nurse :
191184 await runner .run (
192- nurse ,
193- (ua .render () for ua in agents ),
194- timeout = timeout
185+ nurse , (ua .render () for ua in agents ), timeout = timeout
195186 )
196187 await finalize ()
197188 return runner
@@ -201,5 +192,5 @@ async def finalize():
201192 try :
202193 await finalize ()
203194 except SIPpFailure as err :
204- assert ' exit code -9' in str (err )
195+ assert " exit code -9" in str (err )
205196 raise terr
0 commit comments