# Buggy code
def __init__(self, context=None, socket_type=DEALER, shadow=None):
    """Initialize the object and the send and receive state."""
    if context is None:
        context = self._context_class.instance()
    # There are multiple backends which handle shadow differently.
    # It is best to send it as a positional to avoid problems.
    base = super(_Socket, self)
    if shadow is None:
        base.__init__(context, socket_type)
    else:
        base.__init__(context, socket_type, shadow)
    # Initialize send and receive states, which are mapped as:
    #    state:  -1    0   [  1  ]    2       3       4      5
    #    frame:  VIA  PEER [PROTO] USER_ID  MSG_ID  SUBSYS  ...
    state = -1 if self.type == ROUTER else 0
    object.__setattr__(self, "_send_state", state)
    object.__setattr__(self, "_recv_state", state)
    self.immediate = True


# Traceback (ProtocolError)
Traceback (most recent call last):
File "/home/kyle/workspaces/volttron/env/local/lib/python2.7/site-packages/gevent/greenlet.py", line 327, in run
result = self._run(*self.args, **self.kwargs)
File "/home/kyle/workspaces/volttron/volttron/platform/vip/agent/subsystems/pubsub.py", line 280, in subscribe
self.rpc().call(peer, 'pubsub.subscribe', prefix, bus=bus).get()
File "/home/kyle/workspaces/volttron/volttron/platform/vip/agent/subsystems/rpc.py", line 282, in call
self.core().socket.send_vip(peer, 'RPC', [request], msg_id=ident)
File "/home/kyle/workspaces/volttron/volttron/platform/vip/socket.py", line 225, in send_vip
raise ProtocolError('previous send operation is not complete')
ProtocolError: previous send operation is not complete
<Greenlet at 0xb2fc002cL: subscribe(<volttron.platform.vip.agent.subsystems.pubsub.Pub, peer='pubsub', callback=<bound method ActuatorAgent.handle_set of <__main_, prefix=Topic(u'devices/actuators/set'))> failed with ProtocolError

Traceback (most recent call last):
File "/home/kyle/workspaces/volttron/env/local/lib/python2.7/site-packages/gevent/greenlet.py", line 327, in run
result = self._run(*self.args, **self.kwargs)
File "/home/kyle/workspaces/volttron/volttron/platform/vip/agent/subsystems/pubsub.py", line 280, in subscribe
self.rpc().call(peer, 'pubsub.subscribe', prefix, bus=bus).get()
File "/home/kyle/workspaces/volttron/volttron/platform/vip/agent/subsystems/rpc.py", line 282, in call
self.core().socket.send_vip(peer, 'RPC', [request], msg_id=ident)
File "/home/kyle/workspaces/volttron/volttron/platform/vip/socket.py", line 225, in send_vip
raise ProtocolError('previous send operation is not complete')
ProtocolError: previous send operation is not complete
<Greenlet at 0xb2fc007cL: subscribe(<volttron.platform.vip.agent.subsystems.pubsub.Pub, peer='pubsub', callback=<bound method ActuatorAgent.handle_schedule_reques, prefix=Topic(u'devices/actuators/schedule/request'))> failed with ProtocolError

# Fixed code
def __init__(self, context=None, socket_type=DEALER, shadow=None):
    """Initialize the object and the send and receive state."""
    if context is None:
        context = self._context_class.instance()
    # There are multiple backends which handle shadow differently.
    # It is best to send it as a positional to avoid problems.
    base = super(_Socket, self)
    if shadow is None:
        base.__init__(context, socket_type)
    else:
        base.__init__(context, socket_type, shadow)
    # Initialize send and receive states, which are mapped as:
    #    state:  -1    0   [  1  ]    2       3       4      5
    #    frame:  VIA  PEER [PROTO] USER_ID  MSG_ID  SUBSYS  ...
    state = -1 if self.type == ROUTER else 0
    object.__setattr__(self, "_send_state", state)
    object.__setattr__(self, "_recv_state", state)
    object.__setattr__(self, "_Socket__local", self._local_class())
    self.immediate = True