code: def close(self, wait=False):
      # self._log_stderr('Closing {} wait={}'.format(os.getpid(), wait))
      # flush pending logs
      if not self._task_id:
          return
      # Never null the lock, it might be used by internal Python at some point
      # self.lock = None
      self._task_id = None
  
      # shut down the TaskHandler, from this point onwards. No events will be logged
      _background_log = self._background_log
      self._background_log = None
      if _background_log:
          if (
              not _background_log.is_subprocess_mode()
              or _background_log.is_alive()
          ):
              _background_log.stop()
              if wait and (
                  not _background_log.is_subprocess_mode()
                  or _background_log.is_subprocess_mode_and_parent_process()
              ):
                  # noinspection PyBroadException
                  try:
                      timeout = (
                          1.0
                          if _background_log.empty()
                          else self.__wait_for_flush_timeout
                      )
                      _background_log.wait(timeout=timeout)
                      if not _background_log.empty():
                          self._log_stderr(
                              "Flush timeout {}s exceeded, dropping last {} lines".format(
                                  timeout, self._background_log_size
                              )
                          )
                      # self._log_stderr('Closing {} wait done'.format(os.getpid()))
                  except Exception:
                      pass
          else:
              _background_log.send_all_records()
  
      # call super and remove the handler
      super(TaskHandler, self).close()
  
imports: import json
  import sys
  from pathlib2 import Path
  from logging import LogRecord, getLogger, basicConfig, getLevelName, INFO, WARNING, Formatter, makeLogRecord, warning
  from logging.handlers import BufferingHandler
  from .development.worker import DevWorker
  from ...backend_api.services import events
  from ...backend_api.session.session import MaxRequestSizeError
  from ...config import config
  from ...utilities.process.mp import BackgroundMonitor, ForkEvent, ForkQueue
  from ...utilities.process.mp import SafeQueue, SafeEvent
label_desc: Use image node_id 7 for calling the TaskHandler obj's underlying member method code with example usage: obj.close(wait) without return types