code: def wait_until_idle(self):
          
  
          done = threading.Event()
  
          def _callback():
              done.set()
  
          self.defer_until_idle(_callback)
          done.wait()
docs: Block the calling thread until the work queue is (temporarily) empty.
  
          See the detailed discussion under defer_until_idle() for restrictions
          and expected use cases for this method.
  
          This routine will block the calling thread.