class_docstr: A 0MQ Device to be run in the background.
  
  You do not pass Socket instances to this, but rather Socket types::
  
      Device(device_type, in_socket_type, out_socket_type)
  
  For instance::
  
      dev = Device(zmq.QUEUE, zmq.DEALER, zmq.ROUTER)
  
  Similar to zmq.device, but socket types instead of sockets themselves are
  passed, and the sockets are created in the work thread, to avoid issues
  with thread safety. As a result, additional bind_{in|out} and
  connect_{in|out} methods and setsockopt_{in|out} allow users to specify
  connections for the sockets.
  
  Parameters
  ----------
  device_type : int
      The 0MQ Device type
  {in|out}_type : int
      zmq socket types, to be passed later to context.socket(). e.g.
      zmq.PUB, zmq.SUB, zmq.REQ. If out_type is < 0, then in_socket is used
      for both in_socket and out_socket.
      
  Methods
  -------
  bind_{in_out}(iface)
      passthrough for ``{in|out}_socket.bind(iface)``, to be called in the thread
  connect_{in_out}(iface)
      passthrough for ``{in|out}_socket.connect(iface)``, to be called in the
      thread
  setsockopt_{in_out}(opt,value)
      passthrough for ``{in|out}_socket.setsockopt(opt, value)``, to be called in
      the thread
  
  Attributes
  ----------
  daemon : int
      sets whether the thread should be run as a daemon
      Default is true, because if it is false, the thread will not
      exit unless it is killed
  context_factory : callable (class attribute)
      Function for creating the Context. This will be Context.instance
      in ThreadDevices, and Context in ProcessDevices.  The only reason
      it is not instance() in ProcessDevices is that there may be a stale
      Context instance already initialized, and the forked environment
      should *never* try to use it.
class_docstr_tok: ["A","0MQ","Device","to","be","run","in","the","background",".","You","do","not","pass","Socket","instances","to","this",",","but","rather","Socket","types",":",":","Device","(","device_type",",","in_socket_type",",","out_socket_type",")","For","instance",":",":","dev","=","Device","(","zmq.QUEUE",",","zmq.DEALER",",","zmq.ROUTER",")","Similar","to","zmq.device",",","but","socket","types","instead","of","sockets","themselves","are","passed",",","and","the","sockets","are","created","in","the","work","thread",",","to","avoid","issues","with","thread","safety",".","As","a","result",",","additional","bind_","{","in|out","}","and","connect_","{","in|out","}","methods","and","setsockopt_","{","in|out","}","allow","users","to","specify","connections","for","the","sockets",".","Parameters","--","--","--","--","--","device_type",":","int","The","0MQ","Device","type","{","in|out","}","_type",":","int","zmq","socket","types",",","to","be","passed","later","to","context.socket","(",")",".","e.g",".","zmq.PUB",",","zmq.SUB",",","zmq.REQ",".","If","out_type","is","<","0",",","then","in_socket","is","used","for","both","in_socket","and","out_socket",".","Methods","--","--","--","-","bind_","{","in_out","}","(","iface",")","passthrough","for","``","{","in|out","}","_socket.bind","(","iface",")","``",",","to","be","called","in","the","thread","connect_","{","in_out","}","(","iface",")","passthrough","for","``","{","in|out","}","_socket.connect","(","iface",")","``",",","to","be","called","in","the","thread","setsockopt_","{","in_out","}","(","opt",",","value",")","passthrough","for","``","{","in|out","}","_socket.setsockopt","(","opt",",","value",")","``",",","to","be","called","in","the","thread","Attributes","--","--","--","--","--","daemon",":","int","sets","whether","the","thread","should","be","run","as","a","daemon","Default","is","true",",","because","if","it","is","false",",","the","thread","will","not","exit","unless","it","is","killed","context_factory",":","callable","(","class","attribute",")","Function","for","creating","the","Context",".","This","will","be","Context.instance","in","ThreadDevices",",","and","Context","in","ProcessDevices",".","The","only","reason","it","is","not","instance","(",")","in","ProcessDevices","is","that","there","may","be","a","stale","Context","instance","already","initialized",",","and","the","forked","environment","should","*","never","*","try","to","use","it","."]
code: def __init__(self, device_type=QUEUE, in_type=None, out_type=None):
      self.device_type = device_type
      if in_type is None:
          raise TypeError("in_type must be specified")
      if out_type is None:
          raise TypeError("out_type must be specified")
      self.in_type = in_type
      self.out_type = out_type
      self._in_binds = []
      self._in_connects = []
      self._in_sockopts = []
      self._out_binds = []
      self._out_connects = []
      self._out_sockopts = []
      self._random_addrs = []
      self.daemon = True
      self.done = False
  
imports: import time
  from threading import Thread
  from multiprocessing import Process
  from zmq import device, QUEUE, REQ, Context, ETERM, ZMQBindError, ZMQError
label_desc: Use image node_id 1 to create a new Device object  with example: obj = Device(device_type, in_type, out_type)