<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def sync_with_ioloop(self, timeout=None):
 """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. """

        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)