zmq as socket layer

http://zguide.zeromq.org/page:all#Getting-the-Context-Right

They suggest to use a single context though, and pyzmq actually provide a
singleton method (`Context.instane()`). I must have glimpsed codes of pyzmq
and assumed Context() is a singleton.

Still, according to their document: [guide](
http://zguide.zeromq.org/page:all#Getting-the-Context-Right)

```
ØMQ applications always start by creating a *context*, and then using that
for creating sockets. In C, it's the zmq_ctx_new()
<http://api.zeromq.org/3-2:zmq_ctx_new> call. You should create and use
exactly one context in your process. Technically, the context is the
container for all sockets in a single process, and acts as the transport
for inproc sockets, which are the fastest way to connect threads in one
process. If at runtime a process has two contexts, these are like separate
ØMQ instances. If that's explicitly what you want, OK, but otherwise
remember:
```



On Tue, Sep 9, 2014 at 6:23 PM, Maralla <notifications@github.com> wrote:

> In thriftpy/zmq_socket.py:
>
> > +            raise TTransportException(
> > +                type=TTransportException.UNKNOWN,
> > +                message="{} can not send".format(self.__class__.__name__))
> > +
> > +        self.handle.send(buff)
> > +
> > +    def flush(self):
> > +        pass
> > +
> > +
> > +class TZMQServerSocket(TZMQSocketBase):
> > +    def __init__(self, host="127.0.0.1", port=9090):
> > +        self.host = host
> > +        self.port = port
> > +        self.handle = None
> > +        self._ctx = zmq.Context()
>
> A singleton? I don't think so. Every instance of zmq.Context is a
> different object.
> Of course it CAN be a global var and is thread safe. But attach unrelated
> sockets to the same context may course headache effects. When a context is
> terminated, all the sockets open within it should be destroyed
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/eleme/thriftpy/pull/25/files#r17292339>.
>



-- 
Sent from my computer.
@WooParadog <https://www.twitter.com/wooparadog>