Suppose I need to retrieve a job status, and I spawn a new thread to handle the job computation:
def post_view(request):
g = Greenlet.spawn(heavy_job, arg1, arg2)
return json.dumps(default_response)
and then in heavy_job
def heavy_job(...):
# call a 3rd party service to start doing its job
job_id = (....)
request.session['heavy_job_status'] = 'Running'
status = 'Running'
while status == 'Running':
# ask the 3rd party guy "are you still running"
resp = 3rdparty-service.query(job_id, ....)
if resp != 'Running':
return resp
time.sleep(5) # we will monkey patch the time with gevent's timer so no locking
Is this while loop approach really bad for scaling? Or would I rather query the 3rd party service as each ajax request comes in?