Skip to content

Commit 54c0876

Browse files
author
Aleksei Arsenev
committed
workaround for versions < 2.7
1 parent f2636af commit 54c0876

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

distributedflock/Zookeeper.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@
2222
import logging
2323
import socket
2424
import uuid
25+
import os
2526

2627
from ZKeeperAPI import zkapi
2728

29+
PY27 = sys.version_info >= (2,7)
2830

2931
class ZKLockServer(object):
3032
def __init__(self, **config):
@@ -43,7 +45,10 @@ def __init__(self, **config):
4345
raise Exception(msg)
4446

4547
self.lock = config['name']
46-
self.lockpath = '/{}/{}'.format(self.id, self.lock)
48+
if PY27:
49+
self.lockpath = '/{}/{}'.format(self.id, self.lock)
50+
else:
51+
self.lockpath = '/%s/%s' % (self.id, self.lock)
4752
self.locked = False
4853
self.lock_content = socket.gethostname() + str(uuid.uuid4())
4954
except Exception as err:
@@ -65,7 +70,10 @@ def getlock(self):
6570

6671
def set_lock_name(self, name):
6772
self.lock = name
68-
self.lockpath = '/{}/{}'.format(self.id, self.lock)
73+
if PY27:
74+
self.lockpath = '/{}/{}'.format(self.id, self.lock)
75+
else:
76+
self.lockpath = '/%s/%s' % (self.id, self.lock)
6977

7078
def releaselock(self):
7179
try:

0 commit comments

Comments
 (0)