Commit 4e038901 authored by Jim Fulton's avatar Jim Fulton

untabified.

parent 5a85f09e
#!/bin/env python
##############################################################################
#
# Copyright
......@@ -77,8 +76,8 @@ called automatically, if it has one.
This module provides a simple computed attribute implementation and
an example of its usage.
$Id: ComputedAttribute.py,v 1.1 1998/04/07 16:43:21 jim Exp $'''
__version__='$Revision: 1.1 $'[11:-2]
$Id: ComputedAttribute.py,v 1.2 1998/12/04 20:57:46 jim Exp $'''
__version__='$Revision: 1.2 $'[11:-2]
import ExtensionClass
......@@ -98,18 +97,9 @@ if __name__ == "__main__":
class point(ExtensionClass.Base):
def __init__(self, x, y): self.x, self.y = x, y
def __init__(self, x, y): self.x, self.y = x, y
radius=ComputedAttribute(lambda self: sqrt(self.x**2+self.y**2))
radius=ComputedAttribute(lambda self: sqrt(self.x**2+self.y**2))
p=point(2,2)
print p.radius
##############################################################################
#
# $Log: ComputedAttribute.py,v $
# Revision 1.1 1998/04/07 16:43:21 jim
# *** empty log message ***
#
#
......@@ -8,28 +8,28 @@ from time import sleep
class P(Synchronized):
def __init__(self,*args,**kw):
self.count=0
self.count=0
def inc(self):
c=self.count
sleep(rand()/327680.0)
self.count=self.count+1
return c,self.count
c=self.count
sleep(rand()/327680.0)
self.count=self.count+1
return c,self.count
def incn(self,n):
c=self.count
for i in range(n): self.inc()
return c,self.count
c=self.count
for i in range(n): self.inc()
return c,self.count
p=P(1,2,spam=3)
def test():
for i in range(10):
n=3
old,new=p.incn(n)
print old,new
if old+n != new: print 'oops'
n=3
old,new=p.incn(n)
print old,new
if old+n != new: print 'oops'
for i in range(10): thread.start_new_thread(test,())
......
......@@ -10,44 +10,44 @@ with_lock=1
class P(Base):
def __oldcall_method__(self,f,a,k={}):
if with_lock:
try: lock=self.lock
except AttributeError: return apply(f,a,k)
else: return apply(f,a,k)
try:
lock.acquire()
return apply(f,a,k)
finally:
lock.release()
if with_lock:
try: lock=self.lock
except AttributeError: return apply(f,a,k)
else: return apply(f,a,k)
try:
lock.acquire()
return apply(f,a,k)
finally:
lock.release()
__call_method__=apply
def __init__(self,*args,**kw):
self.count=0
if with_lock:
self.lock=lock=ThreadLock.allocate_lock()
self.__call_method__=lock.guarded_apply
self.count=0
if with_lock:
self.lock=lock=ThreadLock.allocate_lock()
self.__call_method__=lock.guarded_apply
def inc(self):
c=self.count
sleep(rand()/32768.0)
self.count=self.count+1
return c,self.count
c=self.count
sleep(rand()/32768.0)
self.count=self.count+1
return c,self.count
def incn(self,n):
c=self.count
for i in range(n): self.inc()
return c,self.count
c=self.count
for i in range(n): self.inc()
return c,self.count
p=P(1,2,spam=3)
def test():
for i in range(10):
n=3
old,new=p.incn(n)
print old,new
if old+n != new: print 'oops'
n=3
old,new=p.incn(n)
print old,new
if old+n != new: print 'oops'
for i in range(10): thread.start_new_thread(test,())
......
......@@ -4,8 +4,8 @@ import ExtensionClass
class C(ExtensionClass.Base):
def __call_method__(self,meth,args,kw={}):
print 'give us a hook, hook, hook...'
apply(meth,args,kw)
print 'give us a hook, hook, hook...'
apply(meth,args,kw)
def hi(self,*args,**kw): print self, args, kw
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment