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

Cherrypy web服务器永远挂起--Matplotlib错误,matplotlib,cherrypy,Matplotlib,Cherrypy,我正在为许多不同的命令行可执行文件创建一个基于web的界面,并在apache后面使用cherrypy(使用mod_rewrite)。我对这一点很陌生,很难正确配置。在我的开发机器上,一切都正常工作,但是当我在第二台机器上安装代码时,我无法让任何东西正常工作 应用程序的基本工作流程是:1。上传一个数据集,2。处理数据(使用python并使用subprocess.call调用可执行文件),3。在网页上显示结果 上传和处理一个数据集后,每次我尝试处理第二个数据集时,系统都会停止响应。我没有在cherr

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

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

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

我使用以下conf文件启动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
我的init.py文件:

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("");
       }
   });
}
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代码:

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("");
       }
   });
}
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出现了一些问题。如果我在Two Point_文件中的figure()命令前后放置print stations,只有第一个会打印。直接从python解释器调用此函数(从等式中删除cherrypy),我会得到以下错误:

无法调用“event”命令:应用程序在执行“event generate$w{{{ThemeChanged}}”时已被销毁 从“ttk::ThemeChanged”中调用过程“ttk::ThemeChanged”第6行

结束(编辑)


我不明白这个错误是什么意思,搜索也不太走运。

老问题,但我得到了相同的问题,我通过在Matplotlib中更改后端解决了这个问题:

import matplotlib
matplotlib.use("qt4agg")

显示所有代码,而不仅仅是配置文件。我目前有19个不同的代码文件用于此项目,看到什么最有帮助?从主文件开始如何。更新的问题显示主文件,以及出现问题的一个案例中的相关代码。此过程运行多长时间?服务器是否比您的计算机慢并且超时?