Scoping rules and threads
<p>This is the program that works (I am able to hear the text to speech in action):   </p>

<pre><code>import pyttsx
import threading

def saythread(location, text):

    engine = pyttsx.init() 

    engine.say(text)
    engine.runAndWait()


e = (1, "please work, oh my god")
t = threading.Thread(target=saythread,args=e,name='sayitthread')
t.start()
</code></pre>

<p>If the program is changed to </p>

<pre><code>import pyttsx
import threading
def saythread(location, text):

    global engine                #(CHANGED) ADDED GLOBAL 

    engine.say(text)
    engine.runAndWait()        

e = (1, "please work, oh my god")

engine = pyttsx.init()                 #(CHANGED) ADDED VARIABLE 
t = threading.Thread(target=saythread,args=e,name='sayitthread')
t.start()
</code></pre>

<p>Then it gets 'stuck' at the line  "engine.runAndWait()" and text to speech doesn't work. I am guessing that the problem lies with the rules of scoping with threads. right?
Basically what I want is a.. a 'handle' to the engine variable in my main thread. So that i can call engine.stop() from the main thread.</p>

<p>Hope I made sense</p>

<p>Thanks</p>
