class_docstr: Create a zmq Context
  
  A zmq Context creates sockets via its ``ctx.socket`` method.
class_docstr_tok: ["Create","a","zmq","Context","A","zmq","Context","creates","sockets","via","its","``","ctx.socket","``","method","."]
docstr: Returns a global Context instance.
  
  Most single-threaded applications have a single, global Context.
  Use this method instead of passing around Context instances
  throughout your code.
  
  A common pattern for classes that depend on Contexts is to use
  a default argument to enable programs with multiple Contexts
  but not require the argument for simpler applications::
  
      class MyClass(object):
          def __init__(self, context=None):
              self.context = context or Context.instance()
  
  .. versionchanged:: 18.1
  
      When called in a subprocess after forking,
      a new global instance is created instead of inheriting
      a Context that won't work from the parent process.
docstr_tok: ["Returns","a","global","Context","instance",".","Most","single-threaded","applications","have","a","single",",","global","Context",".","Use","this","method","instead","of","passing","around","Context","instances","throughout","your","code",".","A","common","pattern","for","classes","that","depend","on","Contexts","is","to","use","a","default","argument","to","enable","programs","with","multiple","Contexts","but","not","require","the","argument","for","simpler","applications",":",":","class","MyClass","(","object",")",":","def","__init__","(","self",",","context=None",")",":","self.context","=","context","or","Context.instance","(",")","..","versionchanged",":",":","18.1","When","called","in","a","subprocess","after","forking",",","a","new","global","instance","is","created","instead","of","inheriting","a","Context","that","wo","n't","work","from","the","parent","process","."]
code: def instance(cls, io_threads=1):
      """Returns a global Context instance.
  
      Most single-threaded applications have a single, global Context.
      Use this method instead of passing around Context instances
      throughout your code.
  
      A common pattern for classes that depend on Contexts is to use
      a default argument to enable programs with multiple Contexts
      but not require the argument for simpler applications::
  
          class MyClass(object):
              def __init__(self, context=None):
                  self.context = context or Context.instance()
  
      .. versionchanged:: 18.1
  
          When called in a subprocess after forking,
          a new global instance is created instead of inheriting
          a Context that won't work from the parent process.
      """
      if (
          cls._instance is None
          or cls._instance_pid != os.getpid()
          or cls._instance.closed
      ):
          with cls._instance_lock:
              if (
                  cls._instance is None
                  or cls._instance_pid != os.getpid()
                  or cls._instance.closed
              ):
                  cls._instance = cls(io_threads=io_threads)
                  cls._instance_pid = os.getpid()
      return cls._instance
  
imports: import atexit
  import os
  from threading import Lock
  from weakref import WeakSet
  from zmq.backend import Context
  from .None import constants
  from .attrsettr import AttributeSetter
  from .constants import ENOTSUP, LINGER, ctx_opt_names
  from .socket import Socket
  from zmq.error import ZMQError
label_desc: Use image node_id 8 for calling the Context obj's underlying member method code with example usage: obj.instance(cls, io_threads) and returns: cls