I am having a cherrypy application which calls a subprocess (subprocess.Popen), it works fine most of the time but sometimes it does not work. When I restart the server, the subprocess.popen get called and works fine. Is there a way to monitor threads in cherrypy and check why the subprocess.popen was not called.
我有一个可以调用子进程(subprocess.Popen)的cherrypy应用程序,它在大多数情况下工作正常,但有时它不起作用。当我重新启动服务器时,subprocess.popen被调用并正常工作。有没有办法监控cherrypy中的线程并检查为什么没有调用subprocess.popen。
Update: The thread continues the rest part of the code and I could the response, only problem is the subprocess is not called
更新:线程继续代码的其余部分,我可以响应,唯一的问题是没有调用子进程
sample code
def fn_test(self,**args):
#return args['md5'].split()[0]
final_html="the complete html"
for i in ['ab','cd','ef']:
if args.has_key(i):
cherrypy.session[i]='checked'
else:
cherrypy.session[i]=''
subprocess.Popen(["python","test.py",'test','aval','bval'])
return final_html
1 个解决方案
#1
For simple and occasional background tasks I recommend cherrypy.process.plugins.BackgroundTask
. Take a look at this question for a complete example and other general consideration about background tasks.
对于简单和偶尔的后台任务,我推荐cherrypy.process.plugins.BackgroundTask。请查看此问题以获取有关后台任务的完整示例和其他一般考虑因素。
Specifically, treating the subprocess
issue, make sure you can reason about your background code's correctness. At least make several logging
entries on start, stop and optionally before/after significant state changes in the module. Also for debugging propose replace your command with something really simple that is guaranteed to be bug-free. For example, date >> date.log
. Then it'll be clear whether the issue originates from background module's flaw or from a process spawning issue.
具体来说,处理子流程问题,请确保您可以推断您的背景代码的正确性。至少在启动,停止和可选地在模块中的重大状态更改之前/之后进行多个日志记录条目。另外,对于调试建议,用一些非常简单的保证无错误的命令替换你的命令。例如,date >> date.log。然后很清楚问题是源于后台模块的缺陷还是来自进程产生问题。
#1
For simple and occasional background tasks I recommend cherrypy.process.plugins.BackgroundTask
. Take a look at this question for a complete example and other general consideration about background tasks.
对于简单和偶尔的后台任务,我推荐cherrypy.process.plugins.BackgroundTask。请查看此问题以获取有关后台任务的完整示例和其他一般考虑因素。
Specifically, treating the subprocess
issue, make sure you can reason about your background code's correctness. At least make several logging
entries on start, stop and optionally before/after significant state changes in the module. Also for debugging propose replace your command with something really simple that is guaranteed to be bug-free. For example, date >> date.log
. Then it'll be clear whether the issue originates from background module's flaw or from a process spawning issue.
具体来说,处理子流程问题,请确保您可以推断您的背景代码的正确性。至少在启动,停止和可选地在模块中的重大状态更改之前/之后进行多个日志记录条目。另外,对于调试建议,用一些非常简单的保证无错误的命令替换你的命令。例如,date >> date.log。然后很清楚问题是源于后台模块的缺陷还是来自进程产生问题。