human
Complete this python program:
def get_instances_to_sync(context, updated_since=None, project_id=None, deleted=True, shuffle=False, uuids_only=False):
assistant
#Here is the Python code you requested.

    """Return a generator that will return a list of active and
    deleted instances to sync with parent cells.  The list may
    optionally be shuffled for periodic updates so that multiple
    cells services aren\t self-healing the same instances in nearly
    lockstep.
    """
    def _get_paginated_instances(context, filters, shuffle, limit, marker):
        instances = objects.InstanceList.get_by_filters(context, filters, sort_key='deleted', sort_dir='asc', limit=limit, marker=marker)
        if (len(instances) > 0):
            marker = instances[(-1)]['uuid']
            instances = list(instances)
            if shuffle:
                random.shuffle(instances)
        return (instances, marker)
    filters = {}
    if (updated_since is not None):
        filters['changes-since'] = updated_since
    if (project_id is not None):
        filters['project_id'] = project_id
    if (not deleted):
        filters['deleted'] = False
    limit = CONF.cells.instance_update_sync_database_limit
    marker = None
    instances = []
    while True:
        if (not instances):
            (instances, marker) = _get_paginated_instances(context, filters, shuffle, limit, marker)
        if (not instances):
            break
        instance = instances.pop(0)
        if uuids_only:
            (yield instance.uuid)
        else:
            (yield instance)