python - Function doesn't work the second time its called in a thread (Pyttsx module) -
edit: drastically reduced code.
on python 2.7 , windows xp
here small program, uses pyttsx module text speech.
working: speaks particular string of text.a new thread ( runnewthread() ) created handles speaking part.
in order stop speaking , used queue communicate new thread , hence stop pyttsx engine.
this works expected. after stopping talking thread , creating new thread, reason engine doesn't speak @ all(inside 2nd new thread). thread function called, variable type of engine = pyttsx.init()
correct, other statements executed correctly , engine.runandwait()
doesn't work. why?
edit: throws exception exception in thread sayitthread (most raised during interpreter shutdown):
import pyttsx import threading threading import * import datetime import os import sys import time 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 target 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 thread1' os._exit(1) print 'after everything' if __name__ == '__main__': wordstosay = """however little known feelings or views of such man may on first entering neighbourhood, truth fixed in minds of surrounding families, considered rightful property of 1 or other of daughters.""" runnewthread(wordstosay) #first thread created. works time.sleep(5) queue.put(true) #send in message stop engine , thread time.sleep(5) runnewthread(wordstosay) #start new thread . thread starts. engine won"t work
edit: debugger says , before running second thread created
t thread: <thread(thread-4, stopped 1328)> _thread__block _condition: <condition(<thread.lock object @ 0x00ad6420>, 0)> _condition__lock lock: <thread.lock object @ 0x00ad6420> _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: <threading._event object @ 0x00e3fdd0> _thread__stderr file: <open file '<stderr>', mode 'w' @ 0x00a650d0> _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
it seems me though thread not alive ( t.isalive() returns false ), variable t still there! me thinks have rid of t variable. tried. gc.collect() , didn't help.
Comments
Post a Comment