Mic92 / python-mpd2

Python library which provides a client interface for the Music Player Daemon.
GNU Lesser General Public License v3.0
352 stars 119 forks source link

Idle and noidle #25

Closed francois2metz closed 11 years ago

francois2metz commented 11 years ago

I may have wrong, but actually the noidle command doesn't works.

If I want to stop idling to quering the status for instance, I have to cancel idling with the noidle command.

client.send_idle('player')
client.noidle()
mpd.PendingCommandError: Cannot execute 'noidle' with pending commands

I'm working on a patch to cancel the idle command when sending noidle, but any insights is welcome.

supermihi commented 11 years ago

Don't you miss the client.fetch_idle() after issuing send_idle()? I am successfully using the idle command as follows:

self.idler.send_idle()
changed = self.idler.fetch_idle()

The problem is of course that fetch_idle() blocks, so you would need another thread for the noidle() command.

francois2metz commented 11 years ago

On 04/09/2013 09:45 AM, Michael Helmling wrote:

Don't you miss the |client.fetch_idle()| after issuing |send_idle()|? I am successfully using the idle command as follows:

self.idler.send_idle() changed = self.idler.fetch_idle()

The problem is of course that |fetch_idle()| blocks, so you would need another thread for the |noidle()| command.

The idle command works. The problem is noidle.

From the readme:

Currently MPDClient is NOT thread-safe. As it use a socket internaly, only one thread can send or receive at the time.

François https://stormz.me

supermihi commented 11 years ago

As far as I understand you have to send fetch_idle() after send_idle() (or use the "select" method as noted in the readme), and that's why your code fails.

only one thread can send or receive at the time.

I know that, but I am using noidle() from a different thread without problems. :-) In fact I don't know how else I should terminate an idling thread when the connection is to be closed.

Mic92 commented 11 years ago

Try send_noidle() instead.

Mic92 commented 11 years ago

Normally, if you use send_ command a fetch_command is expected. Idle and noidle is special case, which isn't currently treated. So this is a bug.