properly close temporary file handles

This commit is contained in:
josch 2012-05-15 12:36:42 +02:00
parent bb9cebab81
commit d3b42b0469

View file

@ -56,7 +56,7 @@ def evaluate_layers_rests(layers, rests, scores, pallet, result_max):
packlist = get_packlist_dict(pallet, articles_to_pack) packlist = get_packlist_dict(pallet, articles_to_pack)
_, tmp = tempfile.mkstemp() tmp_fh, tmp = tempfile.mkstemp()
dicttoxmlfile(packlist, tmp) dicttoxmlfile(packlist, tmp)
# ugly, ugly, ugly, ugly hack - dont copy this... # ugly, ugly, ugly, ugly hack - dont copy this...
@ -66,6 +66,7 @@ def evaluate_layers_rests(layers, rests, scores, pallet, result_max):
score = libpallet.evaluate(sys.argv[1], tmp, sys.argv[3]) score = libpallet.evaluate(sys.argv[1], tmp, sys.argv[3])
if score >= max(scores+[0]): if score >= max(scores+[0]):
result_max[0] = dicttoxmlstring(packlist) result_max[0] = dicttoxmlstring(packlist)
os.close(tmp_fh)
os.remove(tmp) os.remove(tmp)
scores.append(score) scores.append(score)