How do I send connection objects using Pipe() in python?
Question: I am not able to send pipe objects between processes.

    
    
    pipe_i.send(diff_connection_object)
    

I know connection objects are not pickalable. As send() only takes as argument
picklable objects thus I am not able to send the connection object. So how can
I do this ?


Answer: If you use a fork of `multiprocessing` called `multiprocess` then it should
work for almost any connection object you want to send. The fork uses `dill`
instead of `pickle`, to provide better serialization. For example, here's a
`sqlite3.Connection` object.

    
    
    >>> import sqlite3
    >>> c = sqlite3.connect(':memory:')
    >>> c
    <sqlite3.Connection object at 0x1046134b8>
    >>> import multiprocess
    >>> p1,p2 = multiprocess.Pipe()
    >>> p1.send(c)
    >>> c_ = p2.recv()
    >>> c_
    <sqlite3.Connection object at 0x104af8200>
    

It's unclear which connection object is **the** connection object being asked
about. So here's a `_multiprocess.Connection` object being passed with the
`Pipe` from `multiprocess`.

    
    
    >>> c = p1.__class__ 
    >>> p1.send(c)
    >>> c_ = p2.recv()
    >>> c_
    <type '_multiprocess.Connection'>
    

However, in trying to pass the `_multiprocess.Connection` object instance,
instead of the `_multiprocess.Connection` object class… the `send` works just
fine, but the `recv` will unfortunately fail to unpickle the object.

    
    
    >>> p3,p4 = multiprocess.Pipe()
    >>> p1.send(p3)
    >>> p3_ = p2.recv()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.5.dev0-py2.7.egg/dill/dill.py", line 259, in loads
        return load(file)
      File "/Users/mmckerns/lib/python2.7/site-packages/dill-0.2.5.dev0-py2.7.egg/dill/dill.py", line 249, in load
        obj = pik.load()
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 864, in load
        dispatch[key](self)
      File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/pickle.py", line 1089, in load_newobj
        obj = cls.__new__(cls, *args)
    TypeError: Required argument 'handle' (pos 1) not found
    >>> 
    

If the last case worked, you could do some pretty cool stuff, I think. Maybe
it's worth submitting a ticket to `dill` or `multiprocess`, and requesting it
work?

