Re: Rhythmbox Predictive Playback - Weekly Report



Hey Charlotte :)

On 28.06.2008 18:04 Charlotte Curtis wrote:
Next Tuesday is a holiday for me (Canada Day), and some lucky folks
get the Monday off as well, so I'm going to be heading out of internet
range for a few days to enjoy the start of summer.
Yay! Have fun :)

Last week was a learning experience for me: convincing Python to
launch executables without causing the entire Rhythmbox GUI to lock
up.
Hm. Do you know what the problems caused? Is it that Python blocked until the execution of the called programm finished?
How did you try it?

I tried a number of things - threads caused problems because I
was launching the program from a loop and I ended up with hundreds of
little spawned processes, whereas I only wanted one to go at a time.

yeah, threading sucks :P But still, couldn't you use kind of a counter to check whether you've already called the program? (Yeah, thread safety... I know)

If you didn't try the subprocess module[1] already, give it a try!

#!/usr/bin/env python

import time
import subprocess

def dostuff(foo):
    print "Doing Stuff (%s)"%foo
    time.sleep(5)
    print foo

def execdontblock(program):
    p = subprocess.Popen(program, stdout=subprocess.PIPE)
    return p

if __name__=="__main__":
    dostuff("foo")
    p = execdontblock(['sleep','7'])
    dostuff("bar")
    print "Program %s exited" % (p.poll()==None and "has not" or "has")
    dostuff("baz")
    print "Program %s exited" % (p.poll()==None and "has not" or "has")


HTH,
  Tobi (who likes python a bit :) )

[1] http://docs.python.org/lib/module-subprocess.html


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]