@@ -229,7 +229,7 @@ def __initialize__(self, component_ref):
229
229
elif pn_compconf .upper () == 'EXCLUSIVE' :
230
230
self .shared_nodes = False
231
231
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 )
233
233
raise Exception ("Bad 'NODE_ALLOCATION_MODE' value %s" )
234
234
except Exception :
235
235
self .shared_nodes = self .sim_conf ['NODE_ALLOCATION_MODE' ] == 'SHARED'
@@ -306,13 +306,12 @@ def _wait_msg_response(self, msg_id, block=True):
306
306
:py:meth:`messages.ServiceResponseMessage` when available, otherwise
307
307
``None``.
308
308
"""
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' )
316
315
317
316
keep_going = True
318
317
while keep_going :
@@ -340,11 +339,7 @@ def _wait_msg_response(self, msg_id, block=True):
340
339
if not block :
341
340
keep_going = False
342
341
# 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 )
348
343
349
344
def _invoke_service (self , component_id , method_name , * args , ** keywords ):
350
345
r"""
@@ -612,7 +607,7 @@ def launch_task(self, nproc, working_dir, binary, *args, **keywords):
612
607
except KeyError :
613
608
binary_fullpath = ipsutil .which (binary )
614
609
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 )
616
611
raise Exception ("Program %s is not in path or is not executable" % binary )
617
612
else :
618
613
self .binary_fullpath_cache [binary ] = binary_fullpath
@@ -987,18 +982,17 @@ def get_time_loop(self):
987
982
"""
988
983
if self .time_loop is not None :
989
984
return self .time_loop
990
- sim_conf = self .sim_conf
991
985
tlist = []
992
- time_conf = sim_conf ['TIME_LOOP' ]
986
+ time_conf = self . sim_conf ['TIME_LOOP' ]
993
987
994
988
def safe (nums ):
995
989
return len (set (str (nums )).difference (set ("1234567890-+/*.e " ))) == 0
996
990
# generate tlist in regular mode (start, finish, step)
997
991
if time_conf ['MODE' ] == 'REGULAR' :
998
992
for entry in ['FINISH' , 'START' , 'NSTEP' ]:
999
993
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 ]))
1002
996
finish = float (eval (time_conf ['FINISH' ]))
1003
997
start = float (eval (time_conf ['START' ]))
1004
998
nstep = int (eval (time_conf ['NSTEP' ]))
@@ -1628,7 +1622,7 @@ def merge_current_state(self, partial_state_file, logfile=None, merge_binary=Non
1628
1622
bin_name = merge_binary if merge_binary else "update_state"
1629
1623
full_path_binary = ipsutil .which (bin_name )
1630
1624
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 )
1632
1626
raise FileNotFoundError ("Missing executable file %s in PATH" % bin_name )
1633
1627
try :
1634
1628
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
1827
1821
sub_conf_new = ConfigObj (infile = config_file , interpolation = 'template' , file_error = True )
1828
1822
sub_conf_old = ConfigObj (infile = config_file , interpolation = 'template' , file_error = True )
1829
1823
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 )
1831
1825
raise
1832
1826
# Update undefined sub workflow configuration entries using top level configuration
1833
1827
# 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):
1983
1977
except KeyError :
1984
1978
binary_fullpath = ipsutil .which (binary )
1985
1979
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 )
1987
1981
raise Exception ("Program %s is not in path or is not executable" % binary )
1988
1982
else :
1989
1983
self .services .binary_fullpath_cache [binary ] = binary_fullpath
0 commit comments