我试图在python上使用PyV8 (v0.10.1)运行(由pip安装,v1.0-dev),但是应用程序在创建全局上下文时崩溃,因此无法知道出了什么问题,因为没有异常被捕获。这是我的代码:
from flask import Flask, request, Response
import PyV8
try:
from flask.ext.cors import CORS
except ImportError:
import os
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0, parentdir)
from flask.ext.cors import CORS
class Global(PyV8.JSClass):
def hello(self):
print 'Hello'
app = Flask(__name__)
app.config['CORS_HEADERS'] = 'Content-Type'
CORS(app)
@app.route('/', methods=['GET'])
def index():
try:
print 'got to the route'
g = Global()
print 'Global was created'
ctxt = PyV8.JSContext(g)
print 'context was created'
ctxt.enter()
print 'context was entered'
ctxt.eval("hello()")
except Exception as e:
print 'error'
print 'exception occurred, value:', e.value
if __name__ == '__main__':
app.run(host='0.0.0.0') 在此应用程序崩溃前启动GET时,我得到的输出是:
got to the route
Global was created当我试图在没有烧瓶的情况下运行PyV8时,它工作得很好。原因可能是什么?
发布于 2014-10-21 08:12:13
我发现是什么引起了问题--警察。删除本部分后:
try:
from flask.ext.cors import CORS
except ImportError:
import os
parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
os.sys.path.insert(0, parentdir)
from flask.ext.cors import CORS一切都如期而至。我仍然不确定它造成这次事故的原因,这需要进一步的调查,但我决定暂时不使用它。
https://stackoverflow.com/questions/25982603
复制相似问题