2
我試圖在python(v2.7.3)上使用Flask(v0.10.1)運行PyV8(由pip,v1.0-dev安裝),但應用程序在創建Global上下文時崩潰,無法知道發生了什麼問題,因爲沒有發現異常。 這裏是我的代碼:PyV8與Flask崩潰
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它工作正常。 可能是什麼原因?
你如何知道它崩潰並且不掛在'ctxt = PyV8.JSContext(g)'上? – 2014-09-22 20:33:41
我在命令行中運行它,所以應用程序停止運行,返回到命令行,端口是空閒的,我需要再次運行它。 – irenal 2014-09-23 08:11:00