import requests
import time


def request_json_with_backoff(ontology_url):
    """Retrieve an ontology listing from EBI OLS
    returns JSON payload of ontology, or None if unsuccessful
    """
    # add timeout to prevent request from hanging indefinitely
    response = requests.get(ontology_url, timeout=60)
    # inserting sleep to minimize 'Connection timed out' error with too many concurrent requests
    time.sleep(0.25)
    if response.status_code == 200:
        return response.json()
    else:
        return None