threading troubles
Piet van Oostrum
piet at cs.uu.nl
Tue Jul 11 02:59:09 EDT 2006
>>>>> sreekant <skodela at lithium.com> (S) wrote:
>S> Hi folks
>S> What am I doing wrong in the following? I just want to run fluidsynth in
>S> the background.
>S> #########################################
>S> class MyThread(threading.Thread):
>S> def __init__(self, cmd, callback):
>S> self.__cmd = cmd
>S> self.__callback = callback
>S> threading.Thread.__init__(self)
>S> def run(self):
>S> os.system(self.__cmd)
>S> self.__callback('abcd')
>S> return
>S> cmd=midiplay+' '+fmidi
>S> xc=MyThread(cmd,addlog)
>S> xc.start()
>S> ######################
>S> midiplay is 'fluidsynth -ni /home/mysndfont.sf2 mymidi.mid'
>S> addlog is a function which prints the log.
>S> If I run it only with xc.start() it does not run the program as in
>S> os.system. However if I put
>S> xc.start()
>S> xc.run()
>S> then it starts and runs it in foreground with my pygtk ui non responsive.
You shouldn't call run() yourself. It is for the thread library itself.
I tried your example with cmd='ls -l' and it works. If I put a print
'started' after the xc.start(), it prints that before the output of ls -l,
indicating that ls -l is running in the background. (Of course the actual
order is up to the scheduler.) Maybe running it inside a pygtk program
could be different but I wouldn't know why.
--
Piet van Oostrum <piet at cs.uu.nl>
URL: http://www.cs.uu.nl/~piet [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org
More information about the Python-list
mailing list