如何使mod_python等待更新的文本文件读取? 导入cgi def fill(): s=”“”\

如何使mod_python等待更新的文本文件读取? 导入cgi def fill(): s=”“”\,python,cgi,mod-python,textinput,pyinotify,Python,Cgi,Mod Python,Textinput,Pyinotify,键入一个单词: 假设您有三个不同的请求同时进入应用程序。所有这些请求都将试图同时写入和读取相同的文件 为了使上述代码能够处理并发请求,您需要为每个请求/响应使用唯一的文件名。提出一种策略来更改,包括唯一标识符(例如时间戳+客户端ip地址)在输入和输出文件的文件名中。实际上,我认为应该等到应用程序完成执行后,它才应该进入这个语句output\u file=open(“/var/www/cgi-bin/output.txt”,“r”)。read()在应用程序完成作业之前,只有在应用程序更新outpu

键入一个单词:
假设您有三个不同的请求同时进入应用程序。所有这些请求都将试图同时写入和读取相同的文件


为了使上述代码能够处理并发请求,您需要为每个请求/响应使用唯一的文件名。提出一种策略来更改,包括唯一标识符(例如时间戳+客户端ip地址)在输入和输出文件的文件名中。

实际上,我认为应该等到应用程序完成执行后,它才应该进入这个语句
output\u file=open(“/var/www/cgi-bin/output.txt”,“r”)。read()
在应用程序完成作业之前,只有在应用程序更新output.txt后,程序才能继续。。
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 first 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)

   '''Input triggers the application to start its process'''

   output_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 % output_file