code: def flush(self):
          
  
          done = threading.Event()
  
          def _callback():
              done.set()
  
          self.defer(_callback)
          done.wait()
docs: Synchronously wait until this work item is processed.
  
          This has the effect of waiting until all work items queued before this
          method has been called have finished.