简体   繁体   English

Obspy.read() 从 mod_python apache 模块调用时不起作用

[英]Obspy.read() not working when called from mod_python apache module

I'm trying to make a simple web service which reads an MSEED file and outputs some information on that.我正在尝试创建一个简单的 Web 服务,该服务读取 MSEED 文件并输出有关该文件的一些信息。

The most reasonable choice seemed to be using python with the excellent obspy module (A Python Toolbox for seismology/seismological observatories), which is widely used in the seismological community.最合理的选择似乎是使用python和优秀的obspy模块(地震学/地震观测站的 Python 工具箱),它在地震学界被广泛使用。

I succed in reading a file and getting some information from it with this simple python code:我使用这个简单的 python 代码成功读取了一个文件并从中获取了一些信息:

import obspy
import numpy
import sys


my_filename = "SOME FILE"
my_start_time =  "2012-01-01T08:00:00"
my_end_time =  "2012-01-01T09:00:00"

dt = obspy.UTCDateTime(my_start_time)
et = obspy.UTCDateTime(my_end_time)
st = obspy.read(my_filename, starttime=dt, endtime=et)
....then do something....

Now, if I want to implement it as a web service, among the several different choiche I can install the mod_python on Apache, and invoke such script in a bit different way.现在,如果我想将它实现为 Web 服务,在几种不同的选择中,我可以在 Apache 上安装 mod_python,并以稍微不同的方式调用此类脚本。

I do as follows (the script is in a file called test.py ):我做如下(脚本在一个名为test.py的文件中):

from mod_python import util
import obspy
import numpy
import sys

def index(req):
    [...]
    startdate="2012-01-01T08:00:01"
    enddate="2012-01-01T08:10:00"
    myfilename=" SOME FILE"
    dt = obspy.UTCDateTime(startdate)
    et = obspy.UTCDateTime(enddate)

    ##### read file
    st = obspy.read(my_filename, starttime=dt, endtime=et) ******
    [...]

What happens is that on the last line it hangs without giving any error.发生的事情是在最后一行它挂起而没有给出任何错误。 when invoking the script from my server http://localhost.my/cgi-bin/test.py it works well until the last line, then after that it doesn't even print anything but, again WITHOUT OUTPUT ERRORS从我的服务器http://localhost.my/cgi-bin/test.py调用脚本时,它运行良好,直到最后一行,然后它甚至不打印任何内容,但再次没有输出错误

Eveno more weird, if I change the last line with甚至更奇怪,如果我改变最后一行

st = obspy.read(my_filename, headonly=True)

then it works.那么它的工作原理。

What I tried:我试过的:

  1. Changing permission to files/folders.更改文件/文件夹的权限。 The script and the file are in my /var/www/cgi-bin directory.脚本和文件在我的 /var/www/cgi-bin 目录中。 Assigning readable to everyone to files and directory did not work将每个人都可读的分配给文件和目录不起作用
  2. moving files to different folders将文件移动到不同的文件夹
  3. changing the owner of the file/dir (to www-data)更改文件/目录的所有者(到 www-data)

But it still doesn't work.但它仍然不起作用。

I don't understand if it is a problem of the obspy module or some limitation to the apache mod_python.我不明白这是 obspy 模块的问题还是 apache mod_python 的一些限制。

Any idea about how to solve this issue?关于如何解决这个问题的任何想法?

The best answer I received from obspy github issue page was the following我从 obspy github 问题页面收到的最佳答案如下

It seems to be related to a memory allocation issue.它似乎与内存分配问题有关。 You could try to update to the latest ObsPy repository version as we recently made some changes to that and see if that resolves your issue.您可以尝试更新到最新的 ObsPy 存储库版本,因为我们最近对其进行了一些更改,看看是否能解决您的问题。 I am pretty sure that it is not a permissions related issue.我很确定这不是与权限相关的问题。

Otherwise, if you are not tied to using mod_python, you could try out one of the very many and oftentimes very good Python web frameworks.否则,如果您不依赖于使用 mod_python,您可以尝试使用非常多且通常非常好的 Python Web 框架之一。 If you just need it for a simple webservice, a microframework might suit you well:如果您只需要它用于简单的 Web 服务,那么微框架可能很适合您:

http://flask.pocoo.org/ http://www.pylonsproject.org/ http://www.cherrypy.org/ Of course Django might also appeal to you. http://flask.pocoo.org/ http://www.pylonsproject.org/ http://www.cherrypy.org/当然 Django 也可能对你有吸引力。

Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM