Tarmack's home

Threaded MPD

A wrapper class for mpdunicode or python-mpd enabeling threaded communication.

This module is intended as an extension on the mpdunicode or the python-mpd module of J.A. Treuman. It can be used to offload the mpd communication in a separate thread. This is especially useful in graphical clients and plugin components. It stops these components from blocking the main thread normally responsible for updating the gui.

The module calls a callback function with the answer from the mpd server. The callback function is called in the spawned thread. You have to make sure it only calls thread safe code, for instance set an event in your favorite event handler.

The module maps the standard MPDClient methods, so you can still directly call to the protocol methods and they will block.

It is intended to be used in conjunction with the mpdunicode module but can be used with the vanilla python-mpd module as it's found on most systems.

Please note that the threaded idle mode deviates from the protocol by allowing any command while in idle mode. If the server is in idle mode any command other than noidle will be transparently prepended with the noidle command. This is done to make your life easier.


view the code or download threaded mpd.


Some documentation for your convenience:

  • send(command[, args=()][, callback=None][, callbackArgs=None])

    Puts the command on the queue to be send to the server. The optional argument args should be a tuple containing the arguments to the command.
    The optional keyword argument callback should be a function that accepts at least one argument. It is called from the spawned thread with the answer from the server as the first argument. Optionally there can be more arguments added by specifying them in a tuple in callbackArgs.

    If the connection thread encounters an exception it will call the function given in callback with that exception as the first argument. If the connection thread can not recover from the exception it will terminate directly after that.


  • connected()

    Returns True when the connection thread is running and has established a connection.




Valid XHTML 1.0 Transitional Valid CSS!