code: def wait_for_tasks_to_complete(batch_service_client, job_ids, timeout):
      
      timeout_expiration = datetime.datetime.now() + timeout
  
      print("Monitoring all tasks for 'Completed' state, timeout in {}...".format(timeout), end='')
  
      while datetime.datetime.now() < timeout_expiration:
          print('.', end='')
          sys.stdout.flush()
          # tasks = batch_service_client.task.list(job_id)
          # incomplete_tasks = [task for task in tasks if
          #                     task.state != batchmodels.TaskState.completed]
          for (job_id, _) in job_ids:
              tasks = batch_service_client.task.list(job_id)
              incomplete_tasks = [task for task in tasks if
                                  task.state != batchmodels.TaskState.completed]
              if incomplete_tasks:
                  break
          if not incomplete_tasks:
              print()
              return True
          else:
              time.sleep(1)
  
      raise RuntimeError("ERROR: Tasks did not reach 'Completed' state within "
                         "timeout period of " + str(timeout))
docs: Returns when all tasks in the specified job reach the Completed state.
  
      :param batch_service_client: A Batch service client.
      :type batch_service_client: `azure.batch.BatchServiceClient`
      :param str job_id: The id of the job whose tasks should be to monitored.
      :param timedelta timeout: The duration to wait for task completion. If all
      tasks in the specified job do not reach Completed state within this time
      period, an exception will be raised.