From ffd41bf4163f6d83e57b857afc2a1cb3276081a5 Mon Sep 17 00:00:00 2001 From: "J. Alexander Treuman" Date: Thu, 15 Jul 2010 13:52:40 -0400 Subject: [PATCH] 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(). --- mpd.py | 5 +++++ 1 file changed, 5 insertions(+) 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") -- 2.39.5