它不起作用?您的瀏覽器輸出Hello world
?藍牙應用程序?
您是否在單獨的線程中添加run(app, host='localhost', port=8080, debug = True)
調用(此函數調用將阻止)?
例如:
import threading
import time
from bottle import Bottle, run
app = Bottle()
@app.route('/hello')
def hello():
return "Hello World!"
class MyRestServer(threading.Thread):
def __init__(self, app, host, port, debug):
self.app = app
self.host = host
self.port = port
self.debug = debug
threading.Thread.__init__(self)
def run(self):
self.server = self.app.run(
host=self.host,
port=self.port,
debug=self.debug
)
s = MyRestServer(app=app, host='localhost', port=8080, debug=True)
s.start()
# Execution continues
print 'Rest server started'
while True:
time.sleep(2)
print 'Rest server running'
更換while True:
部分與應用程序的其餘部分。
它只有當我把上述代碼放在單獨的文件ABD運行它...但我希望它是另一個Python腳本文件的一部分...然後它不會工作... –