mirror of https://github.com/zulip/zulip.git
log_event: Use 'with' for files
(imported from commit d49b46ecd8aa74679ade3820004d10cb42940ad3)
This commit is contained in:
parent
ccf14b89c2
commit
af36b437b6
|
@ -474,14 +474,14 @@ def get_user_profile_by_id(uid):
|
|||
def log_event(event):
|
||||
assert("timestamp" in event)
|
||||
if not os.path.exists(settings.MESSAGE_LOG + '.lock'):
|
||||
file(settings.MESSAGE_LOG + '.lock', "w").write("0")
|
||||
lock = open(settings.MESSAGE_LOG + '.lock', 'r')
|
||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||
f = open(settings.MESSAGE_LOG, "a")
|
||||
f.write(simplejson.dumps(event) + "\n")
|
||||
f.close()
|
||||
fcntl.flock(lock, fcntl.LOCK_UN)
|
||||
lock.close()
|
||||
with open(settings.MESSAGE_LOG + '.lock', 'w') as lock:
|
||||
lock.write('0')
|
||||
|
||||
with open(settings.MESSAGE_LOG + '.lock', 'r') as lock:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX)
|
||||
with open(settings.MESSAGE_LOG, 'a') as log:
|
||||
log.write(simplejson.dumps(event) + '\n')
|
||||
fcntl.flock(lock, fcntl.LOCK_UN)
|
||||
|
||||
def log_message(message):
|
||||
if not message.sending_client.name.startswith("test:"):
|
||||
|
|
Loading…
Reference in New Issue