On Thu, October 14, 2010 4:10 pm, fons(a)kokkinizita.net wrote:
On Thu, Oct 14, 2010 at 03:04:54PM -0700, Patrick
Shirkey wrote:
In a bit of a time crunch. Can anyone tell me how
to do this properly?
I would like to have a threaded timer to run "cmd" after 5 seconds.
However cmd is normally triggered like this:
os.system(cmd)
But there seems to be an issue with calling os.system(cmd) from
subprocess.popen.
==========================
def do_popen(self, *args):
subprocess.Popen(args[0], shell=True)
def other function
cmd = 'spd-say -t female2 "' + audioText + '"'
args = shlex.split(cmd)
# Add 5 second delay for first view to allow existing speech processes
to
finish
print "do_speech: ",delay
if delay:
print "do_speech: delayed start"
t = threading.Timer(5.0, self.do_popen(cmd))
t.start()
else :
print "do_speech: immediate start"
self.do_popen(cmd)
======================
A bit confusing - you mention os.system() but is not used at all
(nor should it if you use subprocess.Popen().
You didn't tell what happens...
I suspect that if you do this in a function the thread 't' will be
destroyed as soon as that function returns. Making 't' global could
help. (no guarantee -- speculating).
I tried all three suggestions and none of them do the trick.
What happens instead is that the threaded call gets played back the next
time the non threaded call to subprocess.Popen() is called. Although not
every time. But most likely if I wait for a bit longer than the timeout.
This script is very simple it doesn't have a ringbuffer or any way of
tracking itself.
Maybe it's just not possible to create a threaded timer with such a simple
script?
I changed approach and used the priority flag in spd-say. That seems to help.
Cheers.
--
Patrick Shirkey
Boost Hardware Ltd.
"ZPE is not about creating something from nothing: It is about using the
zero point of a wave as a means to transform other forms of potential
energy like magnetic flux, heat, or particle spin into usable energy in
such a way that entropy appears to be reversed."