On Mon, 2002-11-25 at 06:34, Tim Legant wrote:
> David Guerizec <[EMAIL PROTECTED]> writes:
>
> > class Queue:
> > """A simple pending queue."""
> > msgs = []
> > cache = None
...
> >
> > def __init__( self,
> > msgs = [],
> > cache = None,
...
> > pretend = None ):
> >
> > self.msgs = msgs
> > self.cache = cache
...
>
> This class appears to have been written as a Singleton; that is, it is
> not possible to instantiate more than one instance at a time without
> each instance walking all over the other instances' data.
Are you sure about that ? I thought a Singleton uses it's class name to
reference shared member across instances, ie. Queue.cache = cache; and
in fact I've made a little test script:
#!/usr/bin/python
class aClass:
shared = 0
local = 0
def __init__(self, name):
aClass.shared += 1
self.name = name
def inc(self):
self.local += 1
def __repr__(self):
return '[%s]: shared: %s local: %s' %
(self.name, self.shared, self.local)
A = aClass('A')
B = aClass('B')
A.inc()
print A
print B
# prints:
# [A]: shared: 2 local: 1
# [B]: shared: 2 local: 0
Did I understand what you're saying, or am I completly mistaken ?
> I'm curious if
>
> 1) this is intentional? If it is, may I suggest the use of a couple
no, it isn't.
> 2) it's not intentional, would you delete the class variable
> definitions at the beginning of the class, which will cause Python
> to assume that any variables accessed through 'self' are instance
> variables? That will make the class capable of multiple
> instantiations as well as clear up any potential threading issues
> in the future.
of course, since that doesn't seem to change anything, I can do that.
> Any thoughts you have on your class design would be welcome here,
> especially in the case that I'm missing something. I like what you've
> done.
>
>
> Tim
David
_________________________________________________
tmda-workers mailing list ([EMAIL PROTECTED])
http://tmda.net/lists/listinfo/tmda-workers