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()