Skip to content

Commit

Permalink
atomic csv write
Browse files Browse the repository at this point in the history
  • Loading branch information
half-duplex committed Jul 24, 2020
1 parent 9bbfc07 commit 899ff5a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from asyncio import Lock
import logging
from os import fsync, rename

from bot_actions import community_invite, is_admin, valid_token
from chat_functions import send_text_to_room
Expand Down Expand Up @@ -114,9 +115,14 @@ async def _process_request(self, ticket_type):

if tokens[h] == "unused":
tokens[h] = self.event.sender
with open(filename, "w") as f:
filename_temp = filename + ".atomic"
with open(filename_temp, "w") as f:
for key in tokens.keys():
f.write("%s,%s\n" % (key, tokens[key]))
f.flush()
fsync(f.fileno())
rename(filename_temp, filename)

return
else:
logging.info(
Expand Down

0 comments on commit 899ff5a

Please sign in to comment.