From 55f4fc31bdcce213a0b09cf3c4e20393d32540e5 Mon Sep 17 00:00:00 2001 From: Eugene Eeo Date: Sat, 16 Aug 2014 22:59:13 +0800 Subject: [PATCH] use with block to avoid deadlock --- server.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/server.py b/server.py index 793f678..49a47ec 100644 --- a/server.py +++ b/server.py @@ -25,14 +25,13 @@ def mangodb(socket, address): wait.wait() continue if len(cmd_bits) > 1: - lock.acquire(True) - output.write(cmd_bits[1]) - if MANGODB_DURABLE: - output.flush() - os.fsync(output.fileno()) - data = '42' if MANGODB_EVENTUAL else \ - os.urandom(1024).encode('string-escape') - lock.release() + with lock: + output.write(cmd_bits[1]) + if MANGODB_DURABLE: + output.flush() + os.fsync(output.fileno()) + data = '42' if MANGODB_EVENTUAL else \ + os.urandom(1024).encode('string-escape') client.write('OK' + data + '\r\n') client.flush()