hi In my django view ,I am creating a Thread subclass and adding it to a ThreadManager TM to keep in a dictionary with name of thread as key and instance as value.I have implemented TM as a singleton and verified that only one instance of TM exists .However,when the view calls tm.add_mythread() ,I find that the dictionary inside is empty and the currently added instance becomes the only member.
I hope the code will make this clear.Please tell me what I did that was wrong.I unit tested the TM using Dummy thread class and found that the add works correctly .It is only when the view calls tm.add that the above behaviour occurs The view is like this, def add_new_threadobj(request,page_title,template_name): .... if request.method=='POST' and form.is_valid(): tobj=MyThread(some_post_data..) tm=SingletonTM() print 'tm=',tm # to check if same instance tm.add_mythread(tobj) tobj.start() .... TM is a singleton class TM(MySingleton): def __init__(self): self.threads={} def add_thread(self,th): if th.name in self.threads.keys(): print 'already in' else: print 'TM::before::threads:',self.threads self.threads[th.name]=th print 'TM::',self,'add_thread()::added=%s'%th.name print 'TM::after::threads:',self.threads def remove_thread(tname): if tname in self.threads.keys(): del self.threads[tname] When the view add_new_threadobj() is executed a couple of times,this is the print output adding for the first time, tm= <mytm.TM object at 0x94a83ec> TM::before::threads: {} TM:: <mytm.TM object at 0x94a83ec> add_thread()::added=threadname1 TM::after::threads: {'threadname1':<MyThread(threadname1, initial daemon)>} adding another, tm= <mytm.TM object at 0x94a83ec> TM::before::threads: {} TM::after::threads: {'threadname2':<MyThread(threadname2, initial daemon)>} This is what I couldn't make out, the dictionary should now contain 2 kv pairs.Since the tm instance is the same,the self.threads should have printed the initially added thread's name and instance. Please tell me if I am missing something thanks jim -- 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.