import requests
import time
import threading

lock = threading.Lock()
last_call_time = [0]

def fetch_question(base_url: str):
    with lock:
        now = time.time()
        elapsed = now - last_call_time[0]
        if elapsed < 0.1:
            time.sleep(0.1 - elapsed)
        last_call_time[0] = time.time()

    try:
        url = f"{base_url}/api/optionQuestions/random"
        response = requests.get(url, timeout=3)
        response.raise_for_status()
        return response.json()
    except requests.RequestException as e:
        print("请求失败:", e)
        return None
