ipython/ipython — pull request #1556 by minrk (2012-04-06 01:59:19+00:00)
Title: shallow-copy DictDB query results

`db_query()` with default keys pops buffers, and this would result in actually removing the buffers from the record itself. Later calls to `get_result()` would then raise a KeyError, which would go unhandled.

This PR adds shallow-copy to DictDB results, so that changes to the returned dict are not reflected in the db itself.

The bug revealed a general issue: ZMQStreams are closed when an exception is raised in their `on_recv()` callback (following the IOStream pattern, and on the general principal that a socket with failing handlers should not be allowed to continue), which meant that invoking this bug would prevent any future queries to the Hub. So in addition to fixing the particular bug, a decorator is added that catches and logs exceptions, and is applied to all `on_recv()` handlers in IPython.parallel, such that other similar bugs will no longer result in the closure of the socket.

Previously failing tests included at the db and client levels.

repro prior to fix:

```python
from IPython import parallel
rc = parallel.Client()
rc2 = parallel.Client()
# ensure there is at least one result:
rc[:].apply_sync(lambda : 1)
# db_query with default keys results in pop()
rc.db_query({'msg_id' : {'$ne' : None}})
# get_result handler fails with KeyError, so this will hang:
rc2.get_result(rc.history[-1])
```