On 10/12/2010 7:43pm, martvefun wrote:
On 09-12-10 01:37, Mike Dewhirst wrote:
It seems like a good place to put it. Maybe you can test to see if the
threads have been started already?

Here is a singleton which could live in your __init__.py and might
help to record the state of your threading ... or anything else for
that matter.

class singleton(object):
     """ designed by Oren Tirosh and Jeff Pitman """
     def __new__(self, *args, **kwargs):
         if not '_singleton' in self.__dict__:
             slate = object.__new__(self)
             slate.state = {
                 'threads':True,
                 # add other state things as required
             }
             self._singleton = slate
         return self._singleton

hth

Mike

Sorry but I don't really understand how works the function you gave me.

A singleton is a class which guarantees to return exactly the same object every time. It can only create an object once then returns a handle to the existing object instead of creating a new one.

If you initiate your threads and set (in the above example) slate.state['threads'] = True I think you can rely on that and avoid initiating them twice.

I used it once to manage the state of a "switch" where different parts of the project could instantiate a singleton object and read the state, make decisions and update the state reliably for other part of the app.

Mike


In my case, I create several objects like this :

# __init__.py
profile_rec_port = ProfileRecorder()
evaluation_port = EvaluationManager()
...

# evaluationmanager.py
class EvaluationManager(Thread):

     def __init__(self):
         self.port = Queue() # Initialize an infinite empty queue
         Thread.__init__(self) # Initialze the thread
         self.start() # Launch the thread
...



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

Reply via email to