@@ -229,7 +229,7 @@ def __initialize__(self, component_ref):
229229 elif pn_compconf .upper () == 'EXCLUSIVE' :
230230 self .shared_nodes = False
231231 else :
232- self .fwk .error ("Bad 'NODE_ALLOCATION_MODE' value %s" % pn_compconf )
232+ self .fwk .error ("Bad 'NODE_ALLOCATION_MODE' value %s" , pn_compconf )
233233 raise Exception ("Bad 'NODE_ALLOCATION_MODE' value %s" )
234234 except Exception :
235235 self .shared_nodes = self .sim_conf ['NODE_ALLOCATION_MODE' ] == 'SHARED'
@@ -306,13 +306,12 @@ def _wait_msg_response(self, msg_id, block=True):
306306 :py:meth:`messages.ServiceResponseMessage` when available, otherwise
307307 ``None``.
308308 """
309- if msg_id in list (self .finished_calls .keys ()):
310- response = self .finished_calls [msg_id ]
311- del self .finished_calls [msg_id ]
312- return response
313- elif msg_id not in self .incomplete_calls :
314- self .error ('Invalid call ID : %s ' , str (msg_id ))
315- raise Exception ('Invalid message request ID argument' )
309+ try :
310+ return self .finished_calls .pop (msg_id )
311+ except KeyError :
312+ if msg_id not in self .incomplete_calls :
313+ self .error ('Invalid call ID : %s ' , str (msg_id ))
314+ raise Exception ('Invalid message request ID argument' )
316315
317316 keep_going = True
318317 while keep_going :
@@ -340,11 +339,7 @@ def _wait_msg_response(self, msg_id, block=True):
340339 if not block :
341340 keep_going = False
342341 # if this message corresponds to a finish invocation, return the response message
343- if msg_id in list (self .finished_calls .keys ()):
344- response = self .finished_calls [msg_id ]
345- del self .finished_calls [msg_id ]
346- return response
347- return None
342+ return self .finished_calls .pop (msg_id , None )
348343
349344 def _invoke_service (self , component_id , method_name , * args , ** keywords ):
350345 r"""
@@ -612,7 +607,7 @@ def launch_task(self, nproc, working_dir, binary, *args, **keywords):
612607 except KeyError :
613608 binary_fullpath = ipsutil .which (binary )
614609 if not binary_fullpath :
615- self .error ("Program %s is not in path or is not executable" % binary )
610+ self .error ("Program %s is not in path or is not executable" , binary )
616611 raise Exception ("Program %s is not in path or is not executable" % binary )
617612 else :
618613 self .binary_fullpath_cache [binary ] = binary_fullpath
@@ -987,18 +982,17 @@ def get_time_loop(self):
987982 """
988983 if self .time_loop is not None :
989984 return self .time_loop
990- sim_conf = self .sim_conf
991985 tlist = []
992- time_conf = sim_conf ['TIME_LOOP' ]
986+ time_conf = self . sim_conf ['TIME_LOOP' ]
993987
994988 def safe (nums ):
995989 return len (set (str (nums )).difference (set ("1234567890-+/*.e " ))) == 0
996990 # generate tlist in regular mode (start, finish, step)
997991 if time_conf ['MODE' ] == 'REGULAR' :
998992 for entry in ['FINISH' , 'START' , 'NSTEP' ]:
999993 if not safe (time_conf [entry ]):
1000- self .error ('Invalid TIME_LOOP value of %s = %s' % ( entry , time_conf [entry ]) )
1001- raise Exception ('Invalid TIME_LOOP value of %s = %s' % (entry , time_conf [entry ]))
994+ self .error ('Invalid TIME_LOOP value of %s = %s' , entry , time_conf [entry ])
995+ raise ValueError ('Invalid TIME_LOOP value of %s = %s' % (entry , time_conf [entry ]))
1002996 finish = float (eval (time_conf ['FINISH' ]))
1003997 start = float (eval (time_conf ['START' ]))
1004998 nstep = int (eval (time_conf ['NSTEP' ]))
@@ -1628,7 +1622,7 @@ def merge_current_state(self, partial_state_file, logfile=None, merge_binary=Non
16281622 bin_name = merge_binary if merge_binary else "update_state"
16291623 full_path_binary = ipsutil .which (bin_name )
16301624 if not full_path_binary :
1631- self .error ("Missing executable %s in PATH" % bin_name )
1625+ self .error ("Missing executable %s in PATH" , bin_name )
16321626 raise FileNotFoundError ("Missing executable file %s in PATH" % bin_name )
16331627 try :
16341628 msg_id = self ._invoke_service (self .fwk .component_id ,
@@ -1827,7 +1821,7 @@ def create_sub_workflow(self, sub_name, config_file, override=None, input_dir=No
18271821 sub_conf_new = ConfigObj (infile = config_file , interpolation = 'template' , file_error = True )
18281822 sub_conf_old = ConfigObj (infile = config_file , interpolation = 'template' , file_error = True )
18291823 except Exception :
1830- self .exception ("Error accessing sub-workflow config file %s" % config_file )
1824+ self .exception ("Error accessing sub-workflow config file %s" , config_file )
18311825 raise
18321826 # Update undefined sub workflow configuration entries using top level configuration
18331827 # only applicable to non-component entries (ones with non-dictionary values)
@@ -1983,7 +1977,7 @@ def add_task(self, task_name, nproc, working_dir, binary, *args, **keywords):
19831977 except KeyError :
19841978 binary_fullpath = ipsutil .which (binary )
19851979 if not binary_fullpath :
1986- self .services .error ("Program %s is not in path or is not executable" % binary )
1980+ self .services .error ("Program %s is not in path or is not executable" , binary )
19871981 raise Exception ("Program %s is not in path or is not executable" % binary )
19881982 else :
19891983 self .services .binary_fullpath_cache [binary ] = binary_fullpath
0 commit comments