def add_next_tick_callback(self, callback, callback_id=None):
        """ Adds a callback to be run on the next tick.
        Returns an ID that can be used with remove_next_tick_callback."""
        def wrapper(*args, **kwargs):
            # this 'removed' flag is a hack because Tornado has no way
            # to remove a "next tick" callback added with
            # IOLoop.add_callback. So instead we make our wrapper skip
            # invoking the callback.
            if not wrapper.removed:
                self.remove_next_tick_callback(callback_id)
                return callback(*args, **kwargs)
            else:
                return None

        wrapper.removed = False

        def remover():
            wrapper.removed = True

        callback_id = self._assign_remover(callback, callback_id, self._next_tick_callback_removers, remover)
        self._loop.add_callback(wrapper)
        return callback_id
def add_next_tick_callback ( self , callback , callback_id = None ) : def wrapper ( * args , ** kwargs ) : if not wrapper . removed : self . remove_next_tick_callback ( callback_id ) return callback ( * args , ** kwargs ) else : return None wrapper . removed = False def remover ( ) : wrapper . removed = True callback_id = self . _assign_remover ( callback , callback_id , self . _next_tick_callback_removers , remover ) self . _loop . add_callback ( wrapper ) return callback_id
Adds a callback to be run on the next tick.
        Returns an ID that can be used with remove_next_tick_callback.