Haven't started thread but Python throws exception 'Thread already start'
Question: I am writing a producer-consumer application. The producer threads start fine
but when I try to start the consumer threads, I get an exception. Here's the
relevant code:

    
    
    #Producer threads
        for i in range(nThreads):
            self.producerThreads.append(MailThread(i, settings.MAX_EMAILS_PERPASS, self.toFetchQueue, self.rawEmailsQueue, self.stopEvent))
            self.producerThreads[i].start()
            logging.info('Started producer thread %d', i)
    
        #Consumer threads
        #for i in range(settings.MAX_CONS_THREADS):
        try:
            self.consumerThreads.append(ProcessThread(i, settings.STORE_DIRECTORY, settings.DELETE_ONPIPE, self.rawEmailsQueue, self.stopEvent))
            self.consumerThreads[i].start()
            logging.info('Started consumer thread %d', i)
        except Exception, e:
            logging.error('Failed to start consumer thread %s', str(e))
    

Here's the consumer class:

    
    
    import logging, commands, threading, uuid, os, settings, Queue
    
    class ProcessThread(threading.Thread):
    """
    Class to process the emails. 
    """
    def __init__(self, threadCount, storeDirectory, deleteOnPipe, rawEmailsQueue, stopEvent):
        self.threadCount = threadCount
        self.rawEmailsQueue = rawEmailsQueue
        self.stopEvent = stopEvent
        self.storeDirectory = storeDirectory
        self.deleteOnPipe = deleteOnPipe
        threading.Thread.__init__(self)
    
    def run(self):
        logging.info('Run process for consumer thread %d', self.threadCount)
    
        while not self.stopEvent.is_set():
            try:
                emailContainer = rawEmailsQueue.get(False)
                logging.debug('Got a new email')
    
            except Queue.Empty:
                logging.debug('No emails in queue, going to sleep for a while')
                sleep(0.1)
                continue
    

#Rest of processing code

I couldn't get correct indentation, it's fine in my code


Answer: It was a stupid mistake(probably because I've been coding in PHP a lot). I had
initialized the arrays like this:

    
    
    self.producerThreads = self.consumerThreads = []
    

Both arrays referred to the same memory.

