开发者

django generator function not working with real server

I have some code written in django/python. The principal is that the HTTP Response is a generator function. It spits the output of a subprocess on the browser window line by line. This works really well when I am using the django test server. When I use the rea开发者_高级运维l server it fails / basically it just beachballs when you press submit on the page before.

@condition(etag_func=None)
def pushviablah(request):
    if 'hostname' in request.POST and request.POST['hostname']:
        hostname = request.POST['hostname']

        command = "blah.pl --host " + host + " --noturn"
        return HttpResponse( stream_response_generator( hostname, command ), mimetype='text/html')

def stream_response_generator( hostname, command ):
    proc = subprocess.Popen(command.split(), 0, None, subprocess.PIPE, subprocess.PIPE, subprocess.PIPE )
    yield "<pre>"
    var = 1
    while (var == 1):
        for line in proc.stdout.readline():
            yield line

Anyone have any suggestions on how to get this working with on the real server? Or even how to debug why it is not working?


I discovered that the generator function is actually running but it has to complete before the httpresponse throws up a page onscreen. I don't want to have to wait for it to complete before the user sees output. I would like the user to see output as the subprocess progresses.

I'm wondering if this issue could be related to something in apache2 rather than django.


@evolution did you use gunicorn to deploy your app. If yes then you have created a service. I am having a similar kind of issue but with libreoffice. As much as I have researched I have found that PATH is overriding the command path present on your subprocess. I did not have a solution till now. If you bind your app with gunicorn in terminal then your code will also work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜