cherry web服务器永远挂起- Matplotlib错误



我正在为许多不同的命令行可执行文件创建一个基于web的界面,并且在apache后面使用cherryypy(使用mod_rewrite)。我对此非常陌生,并且很难正确配置东西。在我的开发机器上,一切都运行得很好,但是当我在第二台机器上安装代码时,我不能让任何东西正常工作。

应用程序的基本工作流程是:1。上传数据集;2 .处理数据(使用python并使用subprocess.call调用可执行文件);在网页上显示结果

上传并处理一个数据集后,每次尝试处理第二个数据集时,系统都停止响应。我在终端中没有看到任何来自cherryypy进程的输出,也没有在站点日志中看到任何显示发生错误的输出。

我用下面的配置文件启动cherrypy:

[global]
environment: 'production'
log.error_file: 'logs/site.log'
log.screen: True
tools.sessions.on: True
tools.session.storage_type: "file"
tools.session.storage_path: "sessions/"
tools.sessions.timeout: 60
tools.auth.on: True
tools.caching.on: False
server.socket_host: '0.0.0.0'
server.max_request_body_size: 0 
server.socket_timeout: 60
server.thread_pool: 20
server.socket_queue_size: 10
engine.autoreload.on:True

My init.py file:

import cherrypy
import os
import string
from os.path import exists, join
from os import pathsep
from string import split
from mako.template import Template
from mako.lookup import TemplateLookup
from auth import AuthController, require, member_of, name_is
from twopoint import TwoPoint
current_dir = os.path.dirname(os.path.abspath(__file__))
lookup = TemplateLookup(directories=[current_dir + '/templates'])
def findInSubdirectory(filename, subdirectory=''):
  if subdirectory:
    path = subdirectory
  else:
    path = os.getcwd()
  for root, dirs, names in os.walk(path):
      if filename in names:
          return os.path.join(root, filename)
 return None
class Root:
  @cherrypy.expose
  @require()
  def index(self):
      tmpl = lookup.get_template("main.html")
      return tmpl.render(usr=WebUtils.getUserName(),source="")

if __name__=='__main__':
  conf_path = os.path.dirname(os.path.abspath(__file__))
  conf_path = os.path.join(conf_path, "prod.conf")
  cherrypy.config.update(conf_path)
  cherrypy.config.update({'server.socket_host': '127.0.0.1',
                          'server.socket_port': 8080});
  def nocache():
      cherrypy.response.headers['Cache-Control']='no-cache,no-store,must-revalidate'
      cherrypy.response.headers['Pragma']='no-cache'
      cherrypy.response.headers['Expires']='0'
  cherrypy.tools.nocache = cherrypy.Tool('before_finalize',nocache)
  cherrypy.config.update({'tools.nocache.on':'True'})
  cherrypy.tree.mount(Root(), '/')
  cherrypy.tree.mount(TwoPoint(),       '/twopoint')
  cherrypy.engine.start()
  cherrypy.engine.block()
对于发生这种情况的一个例子,我有以下javascript函数调用我的python代码:
function compTwoPoint(dataset,orig){
  // call python code to generate images
  $.post("/twopoint/compTwoPoint/"+dataset,
   function(result){
       res=jQuery.parseJSON(result);
       if(res.success==true){
       showTwoPoint(res.path,orig);
       }
       else{
       alert(res.exception);
       $('#display_loading').html("");
       }
   });
}

调用python代码:

def twopoint(in_matrix):
   """proprietary code, can't share"""    
def twopoint_file(in_file_name,out_file_name):
    k = imread(in_file_name);
    figure()
    imshow(twopoint(k))
    colorbar()
    savefig(out_file_name,bbox_inches="tight")
    close()
class TwoPoint:
    @cherrypy.expose
    def compTwoPoint(self,dataset):
        try:
            fnames=WebUtils.dataFileNames(dataset)
             twopoint_file(fnames['filepath'],os.path.join(fnames['savebase'],"twopt.png"))
        return encoder.iterencode({"success": True})

这些函数一起工作以给出预期的结果。问题是,在处理一个输入文件后,我无法处理第二个文件。我似乎没有从服务器得到响应。

在工作的机器上,我正在运行python 2.7.6和cherrypy 3.2.3。在第二台机器上,我有python 2.7.7和cherrypy 3.3.0。虽然这可以解释行为上的差异,但我想找到一种方法使我的代码足够可移植,以克服版本差异(从旧版本到新版本)

我不知道问题是什么,甚至不知道该搜索什么。我将非常感谢您提供的任何指导或帮助。

(编辑:挖掘一点,我发现一些事情正在发生与matplotlib。如果我在twopoint_file中的figure()命令前后放置print语句,则只打印第一个语句。直接从python解释器中调用这个函数(从方程中删除cherrypy),我得到以下错误:

不能调用"event"命令:当执行"event generate $w{{ThemeChanged}}"时,应用程序已被销毁。过程"ttk::ThemeChanged"第6行从"ttk::ThemeChanged"内部调用

结束编辑)

我不明白这个错误是什么意思,也没有多少运气搜索

老问题,但我得到了同样的问题,我通过改变后端在Matplotlib:

import matplotlib
matplotlib.use("qt4agg")

最新更新