From: J. Alexander Treuman Date: Thu, 15 Jul 2010 17:52:40 +0000 (-0400) Subject: mpd.py: adding fileno() to export socket FD X-Git-Tag: v0.3.0~28 X-Git-Url: http://git.kaliko.me/?p=python-musicpd.git;a=commitdiff_plain;h=ffd41bf4163f6d83e57b857afc2a1cb3276081a5 mpd.py: adding fileno() to export socket FD This allows access to the socket FD for polling if it can be written to/read from. This is useful with, for example, the idle command. Simply call send_idle(), poll the socket FD with select/poll/etc to check if it's ready for reading, and if it is, call fetch_idle() to see what changed. Note that select et al. call fileno() on any objects you pass to them, so you can simply pass the MPDClient instance itself to these functions instead of the FD returned by fileno(). --- diff --git a/mpd.py b/mpd.py index cb16701..7ff17b7 100644 --- a/mpd.py +++ b/mpd.py @@ -389,6 +389,11 @@ class MPDClient(object): self._sock.close() self._reset() + def fileno(self): + if not self._sock: + raise ConnectionError("Not connected") + return self._sock.fileno() + def command_list_ok_begin(self): if self._command_list is not None: raise CommandListError("Already in command list")