Hi,

I am developing an application based on django that also uses some
python modules I have written. My problem is that I need one of my
classes to be a singleton. I use this code to do it (mix of Borg and
singleton):

class SomeClass:
   _shared_state = {}

  def __init__(self):
    self.__dict__ = self._shared_state
    if self.__dict__ != {}:
       return
    self.touched = True
    ...
    # rest of the initialisation code
    ...

This way, I can create as many instances of SomeClass as I need but
each of them shares the same dictionary and I also make sure that the
init code is executed once and only once.

This works fine when I unittest it. But then, I create an instances of
SomeClass in Django and...it does not work...and in the strangest way:
the rest of the initialisation code is executed more than once, but
not everytime.

This behaviour looks as if several different python interpreter were
running, or as if the entire module was reloaded (I started python 2
months ago so I'm not sure under which condition this is possible).
This can only happen if SomeClass._shared_state is wipped away at some
stage, and why and how this happens I can't understand.

Any help or clue about what goes on inside django that could create
this behaviour would be really appreciated.

Thank you in advance.

Regards,
Rodrigue


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to