Skip to content

Commit

Permalink
File Closing in case of Ctrl-C
Browse files Browse the repository at this point in the history
  • Loading branch information
tjones104 authored Nov 5, 2020
1 parent 2c52a1f commit 49ca13b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions transaction-bookings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
nBookingsUpdated = 0
nFlightsUpdated = 0

sqlFile = open("sqlStatements.sql","w+")
sqlFile = open("transaction-bookings.sql","w+")

# Thread def
class worker(threading.Thread):
Expand Down Expand Up @@ -118,8 +118,8 @@ def run(self):
else:
# Inserting and updating
cursor.execute("INSERT INTO ticket \
VALUES ({},'{}',{}, NULL, NULL, NULL);".format(tempTicket_no, tempBook_ref, pId))
sqlFile.write("INSERT INTO ticket \nVALUES ({},'{}',{}, NULL, NULL, NULL);\n\n".format(tempTicket_no,tempBook_ref,pId))
VALUES ({},'{}',{}, '', NULL, NULL);".format(tempTicket_no, tempBook_ref, pId))
sqlFile.write("INSERT INTO ticket \nVALUES ({},'{}',{}, '', NULL, NULL);\n\n".format(tempTicket_no,tempBook_ref,pId))
global nTicketUpdated
nTicketUpdated += 1

Expand Down Expand Up @@ -199,8 +199,11 @@ def main():
for i in threads:
i.join(timeout=1.0)
except (KeyboardInterrupt, SystemExit):
print("\nUser Manual Ctrl-C Caught. Cleaning up. Exiting.")
print("\nUser Manual Ctrl-C Caught. Cleaning up. Closing File. Exiting.")
shutdown_event.set()
finally:
if sqlFile:
sqlFile.close()

print("Successful transactions: " + str(nSuccessful))
print("Unsuccessful transactions: " + str(nUnsuccessful))
Expand Down

0 comments on commit 49ca13b

Please sign in to comment.