del pgworksheet
[learning-git.git] / test.py
blob8025981c0c9b8abdd27ede181b8977ac206166d8
1 import threading
3 class JSQueue:
4 def __init__(self):
5 self.lock = threading.Condition()
6 self.queue = list()
8 def enqueue(self,call):
9 try:
10 self.lock.acquire()
11 self.queue.append(call)
12 self.lock.notify()
13 finally:
14 self.lock.release()
15 def dequeue(self):
16 try:
17 self.lock.acquire()
19 finally:
20 self.lock.release()
23 class JSFunctionCall(object):
24 def __init__(self):
25 self.lock = threading.Lock()
26 self.result = None)
28 def free(self, result):
29 self.result = result
31 def wait(self):
33 class JSFunctionFactory(object):
34 def __init__(self,queue,server):
35 self.queue = queue
36 self.server = server
38 def createFunction(self,args,code,name):
39 return JSFunction(args,code,name,self.queue,self.server)
41 class JSFunction(cached=False):
42 def __init__(self,args,code,name):
43 self.args = args
44 self.name = name
45 self.code = code
46 self.cache = {}
48 def getDefinition(self):
49 return "function %s {\n%s}\n" % (self.name, self.code)
51 def __call__(self,*args):
52 print args,kwargs
54 q = JSQueue()
55 s = AnyServer(q)
56 ff = JSFunctionFactory(q,s)
58 dreieck = ff.createFunction(['a','b'],"""
59 return Math.sqrt(Math.pow(a,2) + Math.pow(b,2));
60 """, "dreieck")
62 for i in range(3,15):
63 print "a=%s,b=%s => c=%s" % (i, i*2, dreieck(i, i*2))