<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def run_with_time_limit(self, cmd, time_limit=SUBMISSION_TIME_LIMIT):
 """Runs docker command and enforces time limit. Args: cmd: list with the command line arguments which are passed to docker binary after run time_limit: time limit, in seconds. Negative value means no limit. Returns: how long it took to run submission in seconds Raises: WorkerError: if error occurred during execution of the submission """

    if time_limit < 0:
      return self.run_without_time_limit(cmd)
    container_name = str(uuid.uuid4())
    cmd = [DOCKER_BINARY, 'run', DOCKER_NVIDIA_RUNTIME,
           '--detach', '--name', container_name] + cmd
    logging.info('Docker command: %s', ' '.join(cmd))
    logging.info('Time limit %d seconds', time_limit)
    retval = subprocess.call(cmd)
    start_time = time.time()
    elapsed_time_sec = 0
    while is_docker_still_running(container_name):
      elapsed_time_sec = int(time.time() - start_time)
      if elapsed_time_sec < time_limit:
        time.sleep(1)
      else:
        kill_docker_container(container_name)
        logging.warning('Submission was killed because run out of time')
    logging.info('Elapsed time of submission: %d', elapsed_time_sec)
    logging.info('Docker retval: %d', retval)
    if retval != 0:
      logging.warning('Docker returned non-zero retval: %d', retval)
      raise WorkerError('Docker returned non-zero retval ' + str(retval))
    return elapsed_time_sec