@@ -43,7 +43,7 @@ def send_shutdown ( self ):
4343 self .send ( "shutdown" , amount_expected = 0 )
4444
4545 def saveStats ( self ):
46- self .pprint ( "client stats after %d queries" % self .nqueries )
46+ self .pprint ( f "client stats after { self .nqueries } queries" )
4747 self .pprint ( "=================================" )
4848 self .pprint ( f"number of results in cache: { len (self .cache )} " )
4949 maxhits = []
@@ -124,8 +124,7 @@ def send ( self, message, amount_expected=32 ):
124124 except (ConnectionRefusedError ,ConnectionResetError ,BrokenPipeError ,ConnectionAbortedError ) as e :
125125 dt = self .getWaitingTime ()
126126 self .ntries += 1
127- self .log ( 'could not connect to %s. trying again in %d seconds' % \
128- ( self .nameAndPort (), dt ) )
127+ self .log ( f'could not connect to { self .nameAndPort ()} . trying again in { dt } seconds' )
129128 time .sleep ( dt )
130129 self .pprint ( f"could not connect in send, after trying { self .ntries } times. aborting" )
131130 raise SModelSError ( f"Could not connect to database in send, tried { self .ntries } times" )
@@ -158,23 +157,26 @@ def findServerStatus ( self ):
158157 def log ( self , * args ):
159158 if type (self .verbose )== str or self .verbose > 35 :
160159 self .setDefaults ()
161- print ( "[databaseClient%d] %s" % ( self .clientid , " " .join (map (str ,args )) ) )
160+ s_args = ' ' .join (map (str ,args ))
161+ print ( f"[databaseClient{ self .clientid } ] { s_args } " )
162162 with open ( self .logfile , "at" ) as f :
163- f . write ( "[databaseClient%d-%s] %s \n " % \
164- ( self .clientid , time . strftime ( "%H:%M:%S" ), " " . join ( map ( str , args )) ) )
163+ asctime = time . strftime ( "%H:%M:%S" )
164+ f . write ( f"[databaseClient { self .clientid } - { asctime } ] { s_args } \n " )
165165 f .close ()
166166
167167 def pprint ( self , * args ):
168168 if type (self .verbose )== str or self .verbose > 25 :
169169 self .setDefaults ()
170- print ( f"[databaseClient{ self .clientid } ] { ' ' .join (map (str ,args ))} " )
170+ s_args = ' ' .join (map (str ,args ))
171+ print ( f"[databaseClient{ self .clientid } ] { s_args } " )
172+ print ( f"[databaseClient{ self .clientid } ] { s_args } " )
171173 with open ( self .logfile , "at" ) as f :
172- f . write ( "[databaseClient%d-%s] %s \n " % \
173- ( self .clientid , time . strftime ( "%H:%M:%S" ), " " . join ( map ( str , args )) ) )
174+ asctime = time . strftime ( "%H:%M:%S" )
175+ f . write ( f"[databaseClient { self .clientid } - { asctime } ] { s_args } \n " )
174176 f .close ()
175177
176178 def nameAndPort ( self ):
177- return "%s:%d" % ( self .servername , self .port )
179+ return f" { self .servername } : { self .port } "
178180
179181 def initialize ( self ):
180182 if hasattr ( self , "sock" ):
@@ -195,19 +197,18 @@ def initialize( self ):
195197 except (socket .timeout ,OSError ,ConnectionRefusedError ,ConnectionResetError ,BrokenPipeError ,ConnectionAbortedError ) as e :
196198 dt = self .getWaitingTime ()
197199 self .ntries += 1
198- self .log ( 'could not connect to %s after %d times. trying again in %d seconds' % \
199- ( self .nameAndPort (), self .ntries , dt ) )
200+ self .log ( f'could not connect to { self .nameAndPort ()} after { self .ntries } times. trying again in { dt } seconds' )
200201 time .sleep ( dt )
201202 self .pprint ( f'could not connect to database in initialize, after trying { self .ntries } times. aborting' )
202- raise SModelSError ( "Could not connect to database in initialize, tried %d times" % self .ntries )
203+ raise SModelSError ( f "Could not connect to database in initialize, tried { self .ntries } times" )
203204
204205
205206def stresstest ( args ):
206207 """ this is one process in the stress test """
207208 verbosity , servername , port = "error" , args [0 ], args [1 ]
208209 nr = args [2 ]
209210 client = DatabaseClient ( servername , port , verbose = verbosity ,
210- logfile = "@@rundir@@/dbclient%d .log" % nr ,
211+ logfile = f "@@rundir@@/dbclient{ nr } .log" ,
211212 clientid = nr )
212213 mmother = random .uniform ( 200 , 900 )
213214 mlsp = random .uniform ( 0 , mmother )
@@ -217,9 +218,8 @@ def stresstest( args ):
217218 mlsp = random .uniform ( 0 , mmother )
218219 msg = "obs:ATLAS-SUSY-2017-01:SRHad-Low:TChiWH:[[%.2f,%.2f],[%.2f,%.2f]]" % \
219220 ( mmother , mlsp , mmother , mlsp )
220- # print ( "client #%d" % pid )
221221 client .query ( msg )
222- print ( " finished %d" % nr )
222+ print ( f"[stresstest] finished { nr } " )
223223
224224if __name__ == "__main__" :
225225 import argparse
0 commit comments