def __new__(cls, opts, io_loop=None):
        '''
        Only create one instance of AsyncAuth per __key()
        '''
        # do we have any mapping for this io_loop
        io_loop = io_loop or tornado.ioloop.IOLoop.current()
        if io_loop not in AsyncAuth.instance_map:
            AsyncAuth.instance_map[io_loop] = weakref.WeakValueDictionary()
        loop_instance_map = AsyncAuth.instance_map[io_loop]

        key = cls.__key(opts)
        auth = loop_instance_map.get(key)
        if auth is None:
            log.debug('Initializing new AsyncAuth for %s', key)
            # we need to make a local variable for this, as we are going to store
            # it in a WeakValueDictionary-- which will remove the item if no one
            # references it-- this forces a reference while we return to the caller
            auth = object.__new__(cls)
            auth.__singleton_init__(opts, io_loop=io_loop)
            loop_instance_map[key] = auth
        else:
            log.debug('Re-using AsyncAuth for %s', key)
        return auth
def __new__ ( cls , opts , io_loop = None ) : io_loop = io_loop or tornado . ioloop . IOLoop . current ( ) if io_loop not in AsyncAuth . instance_map : AsyncAuth . instance_map [ io_loop ] = weakref . WeakValueDictionary ( ) loop_instance_map = AsyncAuth . instance_map [ io_loop ] key = cls . __key ( opts ) auth = loop_instance_map . get ( key ) if auth is None : log . debug ( 'Initializing new AsyncAuth for %s' , key ) auth = object . __new__ ( cls ) auth . __singleton_init__ ( opts , io_loop = io_loop ) loop_instance_map [ key ] = auth else : log . debug ( 'Re-using AsyncAuth for %s' , key ) return auth
Only create one instance of AsyncAuth per __key()