'Synchronization fetch, usually used in xmlrpc thread'

def sync_fetch(self, task):

    if (not self._running):
        return self.ioloop.run_sync(functools.partial(self.async_fetch, task, (lambda t, _, r: True)))
    wait_result = threading.Condition()
    _result = {}
    def callback(type, task, result):
        wait_result.acquire()
        _result[u'type'] = type
        _result[u'task'] = task
        _result[u'result'] = result
        wait_result.notify()
        wait_result.release()
    wait_result.acquire()
    self.ioloop.add_callback(self.fetch, task, callback)
    while (u'result' not in _result):
        wait_result.wait()
    wait_result.release()
    return _result[u'result']
