import cgi
def fill():
s = """\
<html><body>
<form method="get" action="./show">
<p>Type a word: <input type="text" name="word">
<input type="submit" value="Submit"</p>
</form></body></html>
"""
return s
# Receive the Request object
def show(req):
# The getfirst() method returns the value of the f开发者_StackOverflow社区irst field with the
# name passed as the method argument
word = req.form.getfirst('word', '')
print "Creating a text file with the write() method."
text_file = open("/var/www/cgi-bin/input.txt", "w")
text_file.write(word)
text_file.close()
# Escape the user input to avoid script injection attacks
#word = cgi.escape(word)
test(0)
'''Input triggers the application to start its process'''
simplified_file=open("/var/www/cgi-bin/output.txt", "r").read()
s = """\
<html><body>
<p>The submitted word was "%s"</p>
<p><a href="./fill">Submit another word!</a></p>
</body></html>
"""
return s % simplified_file
def test(flag):
print flag
while flag!=1:
x=1
return
This mod_python program's fill method send the text to show method where it writes to input.txt file which is used by my application, till my application is running i don't want rest of the statements to work so i have called a function test, in which i have a while loop which will be looping continuously till the flag is set to 1. If its set to 1 then it will break the while loop and continue execution of rest of the statements. I have made my application to pass test flag variable to set it as 1. according to my logic, it should break the loop and return to show function and continue executing rest but its not happening in that way, its continuously loading the page!
please help me through this..
Thank you.. :)
while flag!=1:
x=1
This loop won't ever finish. When is flag
ever going to change so that flag != 1
is False? Remember, flag
is a local variable so changing it anywhere else isn't going to have an effect -- especially since no other code is going to have the opportunity to run while that loop is still running.
It's really not very clear what you're trying to achieve here. You shouldn't be trying to delay code with infinite loops. I'd re-think your architecture carefully.
it is not the most elegant way to do this, but if you need to change the value of flag outside your method, you should use it as a global
variable.
def test():
global flag # use this everywhere you're using flag.
print flag
while flag!=1:
x=1
return
but to make a waiting method, have a look to python Event() objects, they have a wait() method that blocks until the Event's flag is set.
精彩评论