baudm/mplayer.py — pull request #2 by ekimekim (2013-03-08 15:47:02+00:00)
Title: Add a gevent-friendly Player subclass.

This requires gevent version 1.0rc1 or greater.
There are a few problems (eg. proc.wait()) but it does the main job
of replacing the stdout and stderr processing threads.

It's worth noting that the non-posix fallback for gevent's FileObject is to use threads anyway. So this is effectively a noop on windows.

I used the async.py code as a guideline for how to implement this.
For now, all this does is allow you to use greenlets instead of threads for IO, but I'd also like to fix any other place where non-gevent-friendly blocking may occur, in particular:

* Player._generate_* introspection functions use stdout and stderr objects from Popen, the difficulty here is that the code is not structured in such a way that a subclass can fix that without reimplementing the whole function.
* Player.quit() calls subprocess.wait(), this one is trickier...best bet would be to install a SIGCHLD handler. Not sure about non-posix systems.