Skip to content

Commit 80ad9c1

Browse files
authored
batch replace 'except:' with 'except Exception:' (#703)
The latter will not catch `KeyboardInterrupt` and `SystemExit`. See https://stackoverflow.com/a/18982726/9567349.
1 parent ddbcaa9 commit 80ad9c1

File tree

25 files changed

+53
-53
lines changed

25 files changed

+53
-53
lines changed

dpgen/auto_test/Lammps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ def compute(self,
289289
if len(line) and str(ii) == line[0]:
290290
try:
291291
[float(kk) for kk in line]
292-
except:
292+
except Exception:
293293
continue
294294
stress.append([])
295295
virial.append([])

dpgen/data/gen.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ def make_scale(jdata):
571571
try:
572572
pos_src = os.path.join(os.path.join(init_path, ii), 'CONTCAR')
573573
assert(os.path.isfile(pos_src))
574-
except:
574+
except Exception:
575575
raise RuntimeError("not file %s, vasp relaxation should be run before scale poscar")
576576
scale_path = os.path.join(work_path, ii)
577577
scale_path = os.path.join(scale_path, "scale-%.3f" % jj)
@@ -604,7 +604,7 @@ def make_scale_ABACUS(jdata):
604604
try:
605605
pos_src = os.path.join(os.path.join(init_path, ii), 'OUT.ABACUS/STRU_ION_D')
606606
assert(os.path.isfile(pos_src))
607-
except:
607+
except Exception:
608608
raise RuntimeError("not file %s, vasp relaxation should be run before scale poscar")
609609
scale_path = os.path.join(work_path, ii)
610610
scale_path = os.path.join(scale_path, "scale-%.3f" % jj)
@@ -1238,7 +1238,7 @@ def gen_init_bulk(args) :
12381238
jdata=loadfn(args.PARAM)
12391239
if args.MACHINE is not None:
12401240
mdata=loadfn(args.MACHINE)
1241-
except:
1241+
except Exception:
12421242
with open (args.PARAM, 'r') as fp :
12431243
jdata = json.load (fp)
12441244
if args.MACHINE is not None:

dpgen/data/reaction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def gen_init_reaction(args):
191191
jdata = loadfn(args.PARAM)
192192
if args.MACHINE is not None:
193193
mdata = loadfn(args.MACHINE)
194-
except:
194+
except Exception:
195195
with open(args.PARAM, 'r') as fp:
196196
jdata = json.load(fp)
197197
if args.MACHINE is not None:

dpgen/data/surf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ def make_scale(jdata):
447447
try:
448448
pos_src = os.path.join(os.path.join(init_path, ii), 'CONTCAR')
449449
assert(os.path.isfile(pos_src))
450-
except:
450+
except Exception:
451451
raise RuntimeError("not file %s, vasp relaxation should be run before scale poscar")
452452
scale_path = os.path.join(work_path, ii)
453453
scale_path = os.path.join(scale_path, "scale-%.3f" % jj)
@@ -583,7 +583,7 @@ def gen_init_surf(args):
583583
jdata=loadfn(args.PARAM)
584584
if args.MACHINE is not None:
585585
mdata=loadfn(args.MACHINE)
586-
except:
586+
except Exception:
587587
with open (args.PARAM, 'r') as fp :
588588
jdata = json.load (fp)
589589
if args.MACHINE is not None:

dpgen/data/tools/cessp2force_lin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ def Parser():
290290
try:
291291
name = str(item.split('=')[0])
292292
number = int(item.split('=')[1])
293-
except:
293+
except Exception:
294294
sys.stderr.write("\nERROR: Could not read the -c string\n")
295295
sys.exit()
296296
if number >= max_types:

dpgen/database/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def _parsing_vasp(paths,config_info_dict, id_prefix,iters=True):
8383
iter_record.sort()
8484
dlog.info("iter_record")
8585
dlog.info(iter_record)
86-
except:
86+
except Exception:
8787
pass
8888
for path in paths:
8989
try:

dpgen/database/vasp.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def __init__(self,symbols=None,functional="PBE",pp_file=None,pp_lists=None):
2727
else:
2828
try:
2929
self.potcars=Potcar(symbols=symbols, functional=functional)
30-
except:
30+
except Exception:
3131
warnings.warn ("""Inproperly configure of POTCAR !""")
3232
self.potcars=None
3333

@@ -80,7 +80,7 @@ def from_file(cls,filename):
8080
try:
8181
potcars=Potcar.from_file(filename)
8282
return cls(pp_lists=potcars)
83-
except:
83+
except Exception:
8484
with open(filename,'r') as f:
8585
content=f.readlines()
8686
functional=content[0].strip().split(':')[-1].strip()
@@ -179,7 +179,7 @@ def from_directory(input_dir, optional_files=None):
179179
("POSCAR", Poscar), ("POTCAR", DPPotcar)]:
180180
fullzpath = zpath(os.path.join(input_dir, fname))
181181
sub_d[fname.lower()] = ftype.from_file(fullzpath)
182-
except:
182+
except Exception:
183183
for fname, ftype in [("INCAR", Incar),
184184
("POSCAR", Poscar), ("POTCAR", DPPotcar)]:
185185
fullzpath = zpath(os.path.join(input_dir, fname))

dpgen/dispatcher/ALI.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ def delete_template(self):
352352
response = self.client.do_action_with_exception(request)
353353
flag = 1
354354
break
355-
except:
355+
except Exception:
356356
count += 1
357357
# count = 10 and still failed, continue
358358

@@ -382,7 +382,7 @@ def get_image_id(self, img_name):
382382
return img["ImageId"]
383383
flag = 1
384384
break
385-
except:
385+
except Exception:
386386
count += 1
387387
time.sleep(10)
388388
if not flag:
@@ -441,7 +441,7 @@ def change_apg_capasity(self, capasity):
441441
response = self.client.do_action_with_exception(request)
442442
flag = 1
443443
break
444-
except:
444+
except Exception:
445445
count += 1
446446
time.sleep(10)
447447
if not flag:
@@ -510,5 +510,5 @@ def get_ip(self, instance_list):
510510
else:
511511
ip_list.append(response["Instances"]["Instance"][0]["VpcAttributes"]["PrivateIpAddress"]['IpAddress'][0])
512512
return ip_list
513-
except: return []
513+
except Exception: return []
514514

dpgen/dispatcher/Dispatcher.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def make_dispatcher(mdata, mdata_resource=None, work_path=None, run_tasks=None,
333333
context_type = 'local'
334334
try:
335335
batch_type = mdata['batch']
336-
except:
336+
except Exception:
337337
dlog.info('cannot find key "batch" in machine file, try to use deprecated key "machine_type"')
338338
batch_type = mdata['machine_type']
339339
lazy_local = (mdata.get('lazy-local', False)) or (mdata.get('lazy_local', False))

dpgen/dispatcher/DispatcherList.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ def make_dispatcher(self, ii):
178178
self.dispatcher_list[ii]["dispatcher_status"] = "unsubmitted"
179179
flag = 1
180180
break
181-
except:
181+
except Exception:
182182
count += 1
183183
time.sleep(60)
184184
if not flag:
@@ -201,7 +201,7 @@ def check_dispatcher_status(self, ii, allow_failue=False):
201201
finished = self.dispatcher_list[ii]["dispatcher"].all_finished(self.dispatcher_list[ii]["entity"].job_handler, allow_failue, clean)
202202
if finished:
203203
self.dispatcher_list[ii]["dispatcher_status"] = "finished"
204-
except:
204+
except Exception:
205205
pass
206206
elif status == 1:
207207
# self.dispatcher_list[ii]["dispatcher_status"] = "terminated"

0 commit comments

Comments
 (0)