threading troubles

faulkner faulkner612 at comcast.net
Mon Jul 10 09:59:18 EDT 2006


you don't need twisted to run processes in the background, either.
os.popen* returns a file or set of files representing std streams
immediately
subprocess.Popen is a spiffy little object new in 2.4 and available for
download for 2.3. check the module docstrings for usage tips.

you can use threads, but try doing it the python way instead of the
java way. ;-)
def func(cmd, callback):
    os.system(cmd)
    callback()
xc = threading.Thread(target=func, args=(cmd, callback))
xc.start()


sreekant wrote:
> Hi folks
>
> What am I doing wrong in the following? I just want to run fluidsynth in
> the background.
> #########################################
> class MyThread(threading.Thread):
>      def __init__(self, cmd, callback):
>          self.__cmd = cmd
>          self.__callback = callback
>          threading.Thread.__init__(self)
>
>      def run(self):
>          os.system(self.__cmd)
>          self.__callback('abcd')
>          return
>
>
> cmd=midiplay+' '+fmidi
> xc=MyThread(cmd,addlog)
> xc.start()
>
>
> ######################
> midiplay is 'fluidsynth -ni /home/mysndfont.sf2 mymidi.mid'
> addlog is a function which prints the log.
>
> If I run it only with xc.start() it does not run the program as in
> os.system. However if I  put
> xc.start()
> xc.run()
>
> then it starts and runs it in foreground with my pygtk ui non responsive.
> 
> What am I missing!
> 
> Thanks for any ideas
> sree




More information about the Python-list mailing list