code: def split_crawl_tasks(tasks, concurrency):
      
      if any(tasks) and isinstance(tasks[0], list):
          for seq in tasks:
              if not isinstance(seq, list):
                  raise Exception("Expected a list of tasks")
      else:
          if concurrency > 1:
              chain_size = int(ceil(float(len(tasks)) / concurrency))
              tasks = [
                  chunk for chunk in
                  chunks(
                      iter(tasks),
                      max(1, chain_size)
                  )
              ]
          else:
              tasks = [tasks]
      return tasks
docs: Reorganize tasks according to the tasks max concurrency value.
  
      :param tasks:
        sub-tasks to execute, can be either a list of tasks of a list of list
        of tasks
      :param int concurrency:
        Maximum number of tasks that might be executed in parallel.
  
      :return:
        list of list of tasks.