code: async def start_task(self, task: Task) -> None:
          '''Initialize the task, queue it for execution, add the done callback,
          and keep track of it for when tasks need to be stopped.'''
  
          try:
              Log.debug('task %s starting', task.name)
              before = time.time()
              task.counters['last_run'] = before
  
              task.running = True
              self.running_tasks.add(task)
              await task.run_task()
              Log.debug('task %s completed', task.name)
  
          except CancelledError:
              Log.debug('task %s cancelled', task.name)
  
          except Exception:
              Log.exception('unhandled exception in task %s', task.name)
  
          finally:
              self.running_tasks.discard(task)
              task.running = False
              task.task = None
  
              after = time.time()
              total = after - before
              task.counters['last_completed'] = after
              task.counters['duration'] = totaync def start_task(self, task: Task) -> None:
          '''Initialize the task, queue it for execution, add the done callback,
          and keep track of it for when tasks need to be stopped.'''
  
          try:
              Log.debug('task %s starting', task.name)
              before = time.time()
              task.counters['last_run'] = before
  
              task.running = True
              self.running_tasks.add(task)
              await task.run_task()
              Log.debug('task %s completed', task.name)
  
          except CancelledError:
              Log.debug('task %s cancelled', task.name)
  
          except Exception:
              Log.exception('unhandled exception in task %s', task.name)
  
          finally:
              self.running_tasks.discard(task)
              task.running = False
              task.task = None
  
              after = time.time()
              total = after - before
              task.counters['last_completed'] = after
              task.counters['duration'] = total
docs: Initialize the task, queue it for execution, add the done callback,
          and keep track of it for when tasks need to be stopped.