1

I am coding with python a web page in apache. When I execute in Idle a function of this kind:

def hello():
    import time
    print "hello"
    time.sleep(1)

It prints hello, and then I see how it waits one second to print again the >>>. But in the webserver, it seems like it waits for the full response in order for it to show it altogether, instead of returning each executed command. The problem is that I wanna print a static page while python does other backend stuff. Does anyone know how can I solve this?

EDIT

I want to do a python video record that I have developed. The web is the GUI between the python hardcore and the user. The user calls the server to record a video, so python function starts to work, but the user has to be a way of getting a response, pausing the record, and not just waiting there in front of a white screen.

  • What python web framework is being used? – jmunsch Jun 10 '14 at 18:57
  • @jmunsch I'm not using any, just pure python and apache cgi-bin env –  Jun 10 '14 at 18:58
  • 2
    This is just how the web works, its a request/response cycle; each request must have a response and since the response is delayed (with your sleep call), the cycle isn't complete which is why the browser is waiting. Details on how to avoid this are complicated; you should provide details of the problem you are trying to solve (the application you are writing) with some source code for further help. – Burhan Khalid Jun 10 '14 at 18:58
  • Try using a 'yield', returning a part of the response each time using a generator. the python web server gateway interface (WSGI) supports this. You might need to use mod_wsgi for this. – gilsho Jun 10 '14 at 19:00
  • @BurhanKhalid ok I've just added more details. Thanks –  Jun 10 '14 at 19:02
  • @gilsho but if i'm working already with cgi-bin isn't enough? –  Jun 10 '14 at 19:07
  • is this your *WHOLE* cgi script? – SingleNegationElimination Jun 10 '14 at 19:17

0 Answers0