code: def _thread_body(self) -> None:
      event: Optional[Event]
      # Wait for event in the queue, and process one by one until a
      # finish event is received
      finish_callback = None
      while True:
          event = self._event_queue.get()
          if isinstance(event, RequestFinish):
              finish_callback = event.callback
              break
          self._handle_event(event)
  
      # We've received a finish event. At this point, further Upload requests
      # are invalid.
  
      # After a finish event is received, iterate through the event queue
      # one by one and process all remaining events.
      while True:
          try:
              event = self._event_queue.get(True, 0.2)
          except queue.Empty:
              event = None
          if event:
              self._handle_event(event)
          elif not self._running_jobs:
              # Queue was empty and no jobs left.
              self._pool.shutdown(wait=False)
              if self._async_executor:
                  self._async_executor.stop()
              if finish_callback:
                  finish_callback()
              break
  
imports: import asyncio
  import concurrent.futures
  import logging
  import queue
  import sys
  import threading
  from typing import TYPE_CHECKING, Awaitable, Callable, MutableMapping, MutableSequence, MutableSet, NamedTuple, Optional, Union
  from wandb.errors.term import termerror
  from wandb.filesync import upload_job
  from wandb.sdk.lib.paths import LogicalPath
label_desc: Use image node_id 2 for calling the StepUpload obj's underlying member method code with example usage: obj._thread_body() without return types