Function doesn't work the second time its called in a thread (Pyttsx module)
<p>EDIT: DRASTICALLY reduced the code.</p>

<p>On python 2.7 , windows xp</p>

<p>Here is a small program, that uses the Pyttsx module to do some text to speech. </p>

<p>Working: 
speaks a particular string of text.A new thread ( runNewThread() ) is created which handles the speaking part.</p>

<p>In order to stop the speaking , I used a queue to communicate with the new thread and hence stop the Pyttsx engine.</p>

<p>This all works as expected. However after stopping the talking thread and then creating a  new thread,  then for some reason the engine doesn't speak at all(inside the 2nd new thread). The thread function is properly called, the variable type of the <code>engine = Pyttsx.init()</code> is correct, other statements are executed correctly , its only the <code>engine.runAndWait()</code> doesn't work. Why?</p>

<p>EDIT: IT ALSO throws an exception now <code>Exception in thread sayitthread (most likely raised during interpreter shutdown):</code></p>

<pre><code>import pyttsx
import threading
from threading import *
import datetime
import os
import sys
import time
from Queue import Queue

queue =   Queue()
pauselocation =  0
wordsToSay = ''
play = 0 

#CREATED NEW THREAD
def runNewThread(wordsToSay):    
    e = (queue, wordsToSay)
    t = threading.Thread(target=saythread,args=e,name='sayitthread')
    #t.daemon = True 
    t.start()

#FUNCTION USED AS TARGET FOR NEW THREAD
def saythread(queue , text):
    global pauselocation
    saythread.pause = 0 
    engine = pyttsx.init()
    print ( type(engine) ) 
    saythread.pausequeue1 = False

    def onWord(name, location, length):
        saythread.pausequeue1  = queue.get(False) 
        saythread.pause = location
        if saythread.pausequeue1 == True :
            print 'stopping engine'
            engine.stop() 
            time.sleep(1)

    def engineRun():
        print 'engineRun' , type(engine)
        engine.connect("started-word" , onWord )
        print text
        engine.say(text)
        engine.runAndWait()

    engineRun()
    pauselocation =  saythread.pause
    if saythread.pausequeue1 == False:
        print 'exiting from thread1'
        os._exit(1) 
    print 'after everything'


if __name__ == '__main__':

    wordsToSay = """However little known the feelings or views of such a man may be on his
                    first entering a neighbourhood, this truth is so well fixed in the minds
                    of the surrounding families, that he is considered the rightful property
                    of some one or other of their daughters."""
    runNewThread(wordsToSay) #FIRST THREAD CREATED. THIS WORKS
    time.sleep(5)
    queue.put(True) #SEND IN MESSAGE TO STOP THE ENGINE AND THE THREAD
    time.sleep(5) 
    runNewThread(wordsToSay) #START A NEW THREAD . THE THREAD STARTS. But the ENGINE WON"T WORK
</code></pre>

<p>EDIT:
This is what my debugger says , just before running the second thread is created</p>

<pre><code>t   Thread: &lt;Thread(Thread-4, stopped 1328)&gt;    
    _Thread__block  _Condition: &lt;Condition(&lt;thread.lock object at 0x00AD6420&gt;, 0)&gt;  
        _Condition__lock    lock: &lt;thread.lock object at 0x00AD6420&gt;    
        _Condition__waiters list: []    
            __len__ int: 0  
        _Verbose__verbose   bool: False 
    _Thread__daemonic   bool: False 
    _Thread__ident  int: 1328   
    _Thread__initialized    bool: True  
    _Thread__name   str: Thread-4   
    _Thread__started    _Event: &lt;threading._Event object at 0x00E3FDD0&gt; 
    _Thread__stderr file: &lt;open file '&lt;stderr&gt;', mode 'w' at 0x00A650D0&gt;    
    _Thread__stopped    bool: True  
    _Verbose__verbose   bool: False 
    additionalInfo  PyDBAdditionalThreadInfoWithCurrentFramesSupport: State:1 Stop:None Cmd: None Kill:False    
    daemon  bool: False 
    ident   int: 1328   
    name    str: Thread-4   
</code></pre>

<p>IT seems to me that even though the thread is not alive ( t.isAlive() returns false ), the variable t is still there! me thinks I have to get rid of this t variable. I tried. gc.collect() , but it didn't help.</p>
