PYTHON   53

device

Guest on 30th April 2022 11:52:53 PM

  1. # Copyright (C) PyZMQ Developers
  2. # Distributed under the terms of the Modified BSD License.
  3.  
  4. import zmq
  5. from zmq.green import Poller
  6.  
  7. def device(device_type, isocket, osocket):
  8.     """Start a zeromq device (gevent-compatible).
  9.    
  10.    Unlike the true zmq.device, this does not release the GIL.
  11.  
  12.    Parameters
  13.    ----------
  14.    device_type : (QUEUE, FORWARDER, STREAMER)
  15.        The type of device to start (ignored).
  16.    isocket : Socket
  17.        The Socket instance for the incoming traffic.
  18.    osocket : Socket
  19.        The Socket instance for the outbound traffic.
  20.    """
  21.     p = Poller()
  22.     if osocket == -1:
  23.         osocket = isocket
  24.     p.register(isocket, zmq.POLLIN)
  25.     p.register(osocket, zmq.POLLIN)
  26.    
  27.     while True:
  28.         events = dict(p.poll())
  29.         if isocket in events:
  30.             osocket.send_multipart(isocket.recv_multipart())
  31.         if osocket in events:
  32.             isocket.send_multipart(osocket.recv_multipart())

Raw Paste


Login or Register to edit or fork this paste. It's free.