Only close files when they've been opened
This commit is contained in:
parent
27f8b6d5d0
commit
bfb7f477af
|
@ -19,10 +19,9 @@ def startup():
|
||||||
try:
|
try:
|
||||||
fd = open(filename)
|
fd = open(filename)
|
||||||
data = json.load(fd)
|
data = json.load(fd)
|
||||||
|
fd.close()
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("DB file not found, creating on POST/write.")
|
print("DB file not found, creating on POST/write.")
|
||||||
finally:
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
print("Read", len(data), "quizzes from DB")
|
print("Read", len(data), "quizzes from DB")
|
||||||
|
|
||||||
|
@ -54,10 +53,9 @@ def post():
|
||||||
try:
|
try:
|
||||||
fd = open(filename, 'w+')
|
fd = open(filename, 'w+')
|
||||||
json.dump(data, fd, indent=2)
|
json.dump(data, fd, indent=2)
|
||||||
|
fd.close()
|
||||||
except e:
|
except e:
|
||||||
print("Failed to open/create DB file for writing:", e)
|
print("Failed to open/create DB file for writing:", e)
|
||||||
finally:
|
|
||||||
fd.close()
|
|
||||||
|
|
||||||
return id, 201
|
return id, 201
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue