code: def sync_with_ioloop(self, timeout=None):
          
          in_ioloop = self._server.in_ioloop_thread()
          if in_ioloop:
              f = tornado_Future()
          else:
              f = Future()
  
          def cb():
              f.set_result(None)
  
          self.ioloop.add_callback(cb)
  
          if in_ioloop:
              return f
          else:
              f.result(timeout)
docs: Block for ioloop to complete a loop if called from another thread.
  
          Returns a future if called from inside the ioloop.
  
          Raises concurrent.futures.TimeoutError if timed out while blocking.