make code thread safe and immune too
This commit is contained in:
parent
51b92a1ebf
commit
3e9c06c081
1 changed files with 9 additions and 6 deletions
15
doku.py
15
doku.py
|
@ -14,15 +14,18 @@ class DokuWiki:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.callcache = {}
|
self.callcache = {}
|
||||||
|
|
||||||
def __getattr__(self, callback):
|
def __getattr__(self, method):
|
||||||
self.callback = callback
|
def wrap(method):
|
||||||
return self.__dokucall
|
def wrapped(*args):
|
||||||
|
return self.__call(method, *args)
|
||||||
|
return wrapped
|
||||||
|
return wrap(method)
|
||||||
|
|
||||||
def __dokucall(self, *args):
|
def __call(self, method, *args):
|
||||||
args = list(args)
|
args = list(args)
|
||||||
key = "%s:%s" % (self.callback, ",".join(args))
|
key = "%s:%s" % (method, ",".join(args))
|
||||||
if not self.callcache.has_key(key):
|
if not self.callcache.has_key(key):
|
||||||
cmd = ['./doku.php', self.callback ] + args
|
cmd = ['./doku.php', method ] + args
|
||||||
res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate()
|
res = subprocess.Popen(cmd, stdin = None, stdout = subprocess.PIPE, stderr = sys.stderr, close_fds = True).communicate()
|
||||||
print "%s->%s" % (cmd, res)
|
print "%s->%s" % (cmd, res)
|
||||||
self.callcache[key] = res[0]
|
self.callcache[key] = res[0]
|
||||||
|
|
Loading…
Reference in a new issue