@csrf_exempt
@RequireLogin(role='admin')
def stop(request):
    """
    Stop the proxy.
    """
    if request.method != "GET":
        return HttpResponse(status=405)

    from api.models import redis_wrapper
    r = redis_wrapper.init_redis()
    response_key = str(ObjectId())
    redis_wrapper.publish_to_proxy(json.dumps({
        "operation": "stop",
        "param": None,
        "key": response_key,
    }))
    for i in range(0, 50):
        response = r.get(response_key)
        if response is not None:
            try:
                response = json.loads(response)
            except __HOLE__:
                return HttpResponse(status=500)
            if ('code' in response) and (response['code'] == 200):
                return JsonResponse({"proxyResponse": response}, status=200)
            else:
                return HttpResponse(status=500)
        else:
            time.sleep(.1)  # sleep 100ms
    return HttpResponse(status=408)
dataset/ETHPy150Open emccode/heliosburn/heliosburn/django/hbproject/api/views/proxy.py/stop