zeromq/pyzmq — Issue #166: ZMQStream.on_recv/on_send should pass stream to callbacks
Author: minrk
Created: 2012-01-19 22:08:11+00:00
State: open

Currently, the on_recv/on_send system only passes the *message* to the callback, but they should really pass both the stream and the message. This is the way the czmq reactor behaves, and it makes it easier to use the same callback with multiple streams.

The only tricky thing here is how to add this in a sensible way that does not break current apps that only expect the one argument.

For now, this behavior can be emulated with closures and intermediary functions:

```python
def handle_recv(stream, msg):
dostuff()

for s in streams:
s.on_recv(lambda msg: handle_recv(s,msg))
```

But this is suboptimal.