original_docstring: Clean up & notify :obj:`changes_channel` of no more messages.
  
          This method collects all tasks that this particular class
          initiated, and will cancel them if they don't complete within
          the configured timeout period.
  
          Once all tasks are done, ``None`` is added to the
          :obj:`changes_channel` to signify that it has no more work to
          process. Then the HTTP session attached to the :obj:`dns_client`
          is properly closed.
          
docstring: Clean up & notify :obj:`changes_channel` of no more messages.
  This method collects all tasks that this particular class
  initiated, and will cancel them if they don't complete within
  the configured timeout period.
  
  Once all tasks are done, ``None`` is added to the
docstring_tokens: Clean up & notify : obj : ` changes_channel ` of no more messages . This method collects all tasks that this particular class initiated and will cancel them if they don ' t complete within the configured timeout period . Once all tasks are done ` ` None ` ` is added to the
code: async def cleanup(self):
          """Clean up & notify :obj:`changes_channel` of no more messages.
  
          This method collects all tasks that this particular class
          initiated, and will cancel them if they don't complete within
          the configured timeout period.
  
          Once all tasks are done, ``None`` is added to the
          :obj:`changes_channel` to signify that it has no more work to
          process. Then the HTTP session attached to the :obj:`dns_client`
          is properly closed.
          """
          all_tasks = asyncio.Task.all_tasks()
          tasks_to_clear = [
              t for t in all_tasks if t._coro.__name__ in self._ASYNC_METHODS
          ]
          sleep_for = 0.5  # half a second
          iterations = self.cleanup_timeout / sleep_for
  
          while iterations:
              tasks_to_clear = [t for t in tasks_to_clear if not t.done()]
              if not tasks_to_clear:
                  break
  
              await asyncio.sleep(sleep_for)
              iterations -= 1
  
          # give up on waiting for tasks to complete
          if tasks_to_clear:
              msg = (f'The following tasks did not complete in time and are '
                     f'being cancelled: {tasks_to_clear}')
              logging.warning(msg)
              for task in tasks_to_clear:
                  task.cancel()
  
          await self.changes_channel.put(None)
          # TODO (lynn): add metrics.flush call here once aioshumway is released
          await self.dns_client._session.close()
  
          msg = ('Reconciliation of desired records against actual records in '
                 'Google DNS is complete.')
          logging.info(msg)
code_tokens: async def cleanup ( self ) : all_tasks = asyncio . Task . all_tasks ( ) tasks_to_clear = [ t for t in all_tasks if t . _coro . __name__ in self . _ASYNC_METHODS ] sleep_for = 0.5 iterations = self . cleanup_timeout / sleep_for while iterations : tasks_to_clear = [ t for t in tasks_to_clear if not t . done ( ) ] if not tasks_to_clear : break await asyncio . sleep ( sleep_for ) iterations -= 1 if tasks_to_clear : msg = ( f'The following tasks did not complete in time and are ' f'being cancelled: {tasks_to_clear}' ) logging . warning ( msg ) for task in tasks_to_clear : task . cancel ( ) await self . changes_channel . put ( None ) await self . dns_client . _session . close ( ) msg = ( 'Reconciliation of desired records against actual records in ' 'Google DNS is complete.' ) logging . info ( msg )
short_docstring: Clean up & notify :obj:`changes_channel` of no more messages.
short_docstring_tokens: Clean up & notify : obj : ` changes_channel ` of no more messages .
comment: """Clean up & notify :obj:`changes_channel` of no more messages.
  
          This method collects all tasks that this particular class
          initiated, and will cancel them if they don't complete within
          the configured timeout period.
  
          Once all tasks are done, ``None`` is added to the
          :obj:`changes_channel` to signify that it has no more work to
          process. Then the HTTP session attached to the :obj:`dns_client`
          is properly closed.
          """$SEP$# half a second$SEP$# give up on waiting for tasks to complete$SEP$# TODO (lynn): add metrics.flush call here once aioshumway is released