Pep 342 (val = yield MyGenerator(foo)), synchronous os.system() that doesn't block gui event loops

Nick Craig-Wood nick at craig-wood.com
Thu Jul 23 16:29:57 EDT 2009


Ville Vainio <vivainio at gmail.com> wrote:
>  Has anyone implementing something like what the subject line
>  indicates?
> 
>  The idea:
> 
>  To run functions that execute a series of system commands without
>  blocking the ui, *and* without adding state machine logic.
> 
>  The syntax would be something like:
> 
>  def work():
> 
>    showstatus("building")
>    r = yield runshell("make")
>    showstatus("installing")
>    r = yield runshell("make install")
>    showstatus("Success")
> 
>  mygui.startwork(work)
>  # returns immediately, runs work() gradually in the background.
> 
>  The catch is that showstatus() would need to be run in the mainloop,
>  so running the whole thing in a thread is a no-go.
> 
>  I imagine runshell() would be implemented in terms of QProcess, or
>  subprocess.Popen/os.system and a worker thread.
> 
>  Anyone done this already, or do I have to roll my own?

You might want to look at twisted, in particular

  http://twistedmatrix.com/trac/wiki/DeferredGenerator

-- 
Nick Craig-Wood <nick at craig-wood.com> -- http://www.craig-wood.com/nick



More information about the Python-list mailing list