Python 带Bottlpy的Globale变量(在后台)
我需要在我的程序中使用全局变量,使flask或瓶子作为Web服务运行。到目前为止,我用瓶子作为线索,在这里找到了一个片段: 我基本上想转到localhost:8080/hello,将全局变量test增加一个:Python 带Bottlpy的Globale变量(在后台),python,bottle,Python,Bottle,我需要在我的程序中使用全局变量,使flask或瓶子作为Web服务运行。到目前为止,我用瓶子作为线索,在这里找到了一个片段: 我基本上想转到localhost:8080/hello,将全局变量test增加一个: #!/usr/bin/env python from bottle import route, run from multiprocessing import Process @route('/hello') def hello(): global test test =
#!/usr/bin/env python
from bottle import route, run
from multiprocessing import Process
@route('/hello')
def hello():
global test
test = test + 1
return test
def main():
global test
test = 0
t = Process(target=bottle.run(host='0.0.0.0', port=8080))
t.daemon = True
t.start()
while(True)
print test
time.sleep(0.5)
if __name__ == "__main__":
main()
如果我使用浏览器转到localhost:8080/hello,我会得到:
错误500:内部服务器错误-未处理的异常
我看不出有什么例外,即使有
try
global test
test = test + 1
return test
except Exception e
print e
您正在从
hello
返回一个int
,但需要返回一个(字符串的)iterable
提示:在调用run
时添加debug=True
,以便在响应中获得更好的错误信息
t=Process(target=run(host='0.0.0',port=8080,debug=True))
您正在从hello
返回一个int
,但需要返回一个iterable(字符串)
提示:在调用run
时添加debug=True
,以便在响应中获得更好的错误信息
t=Process(target=run(host='0.0.0',port=8080,debug=True))
您是如何启动程序的?您应该在stderr上看到错误(回溯)。您发布的代码将不会运行,它有语法错误。您确定发布的代码与实际运行的代码相同吗?例如,while(True)
行是一个语法错误。您是如何启动程序的?您应该在stderr上看到错误(回溯)。您发布的代码将不会运行,它有语法错误。您确定发布的代码与实际运行的代码相同吗?例如,行while(True)
是一个语法错误。