title: Starting a simple python thread on Django init
body: <p>I have just now started to work with django. On my development environment I use to the start the django server using:</p>
  
  <pre><code>python manage.py runserver 0.0.0.0:8000
  </code></pre>
  
  <p>and my web application is working as expected still I have many errors with that too... But as of now I want to run a background thread on the server init and I need some guidance.</p>
  
  <p>Here is the thread code which I am trying to add:</p>
  
  <pre><code>def synchronized(L):
      def lock_around(f):
          def locked(*a, **k):
              with L:
                  return f(*a, **k)
          locked.__name__ = f.__name__
          locked.__doc__ = f.__doc__
          return locked
      return lock_around
  
  
  class ProcessMsgQueue:
  
      def __init__(self):
          try:
              print "jaojdajdoaj"
              self.dataCounter = 0
              self.errorCounter = 0
              self.setupQueueTable()
              self.wrapperFuns = structureWrapper.WrapperClass()
              msgStruct = MsgStruct()
              self.VerifyMsgQueue()
          except:
              raise
  
      def setupQueueTable(self):
          self.hash_object = QueueHandler("queue_details")
          self.hash_object.EnableListener()
          self.hash_object.createNewHashRef()
          self.hash_object.create("dataMsgQueue")
          self.hash_object.create("errorMsgQueue")
  
      @synchronized(lock)     
      def pendMessage(self):
          print "pendMsg"
          try:
              res_mq = posix_ipc.MessageQueue(RESPONSE_QUEUE_NAME)
              res_msg = None
              res_msg,t_size = res_mq.receive()
              #print res_msg.encode('hex')
              return res_msg
          except Exception as e:
              print e
              raise
          finally:
              res_mq.close()
  
      def VerifyMsgQueue(self):
          while(self.hash_object.Queuelisten):
              try:
                  posixQueueMessage=self.pendMessage()
                  if not posixQueueMessage == None:
                      msgStruct = None
                      msgStruct = MsgStruct()
                      self.wrapperFuns.memCopy(posixQueueMessage,msgStruct)
                      if(msgStruct.msgType == palMsgType["DOOR_OPEN_INSERVICE_MSG"]):
                          print "Added Error to hastable"
                          self.hash_object.set("errorMsgQueue",self.errorCounter,msgStruct.msgBuf)
                      else:
                          print "Added Data to hastable"
                          self.hash_object.set("dataMsgQueue",msgStruct.msgType,msgStruct.msgBuf)
                      posixQueueMessage=None
              except:
                  raise
  </code></pre>