Below is what I want to do in django views.
import requests, time
def SOME_VIEW_FOR_AJAX(request):
if request.is_ajax():
response = requests.get('API_URL_START_TASK')
# response is like {'ready':false, 'status':'PENDING'}
while not response['ready']:
response = requests.get('API_URL_CHECK_TASK')
time.sleep(1)
result = response.get()
# SOME MORE WORKS ...
via api (celery is on the other PC), this view initiates a celery task, constantly checks a status of the task, and gets the result if the task is done.
Here I concern the presence of time.sleep. This SO POST tells that the use of time.sleep is not appropriate because it holds a current thread. Is there a possible replacement of time.sleep for using django views? or is it allowable to use time.sleep for such a usage?
I am using Django 1.8.6, Apache 2.4 with mod_wsgi, Windows Server 2012 R2. Thanks in advance.