SoCo/SoCo — pull request #121 by lawrenceakka (2014-05-05 14:52:06+00:00)
Title: Eventing - you asked for it!

An implementation of UPnP eventing requiring no external dependencies at all (cf #90). It uses standard lib modules only, and multi-threading. The event listener runs in its own thread and puts all events onto the `soco.events.event_queue` instance. They can can be retrieved from there by the main thread using standard python Queue methods (`get_nowait()` and `get()`). No XML processing is done at the moment, but this would be relatively easy to add. So would broadcast signalling using something like [Blinker](http://pythonhosted.org/blinker/)

Of course if you want to use this in a program, you are going to have to write an event loop (or use someone else's) to check for incoming events from time to time! Here is a short example:

```python
try:
from queue import Empty
else: # Py2.7
from Queue import Empty

import soco
from soco.events import event_queue
# pick a device
devices=list(soco.discover())[0]
# Subscribe to rendering control events. Or you could use
# avTransport, contentDirectory etc. No need to start the
# event listener - this is handled automatically
device.renderingControl.subscribe()

# A simple event loop. Print out the events as they arise.
# Try using the volume control on the device whilst this
# is running.
while True:
try:
event = event_queue.get_nowait()
print event
except Empty:
pass
```

There is also an `iter_event_vars()` method for each service which provides an iterator over the eventable variables for that service, so you can see what they are.