我使用Python和Tornado來構建具有jQuery UI滑塊元素的基本應用程序。我的目標是,當用戶與滑塊交互時,它將被髮送一個值給一個python函數,並且結果將顯示在python控制檯中。 我custom.js是:tornado.gen.BadYieldError:產生未知對象無
$(function() {
$("#slider-range-max").slider({
min : 0,
max : 100,
slide : function(event, ui) {
$("#amount").val(ui.value);
ajax({
url: "/action",
data: {parameter:ui.value},
});
},
});
$("#amount").val($("#slider-range-max").slider("value"));
});
main.py
define("port", default=8888, help="run on the given port", type=int)
class Application(tornado.web.Application):
def __init__(self):
handlers = [
(r"/", AuxHandler),
(r"/action", MainHandler)
]
settings = {
"template_path": Settings.TEMPLATE_PATH,
"static_path": Settings.STATIC_PATH,
}
tornado.web.Application.__init__(self, handlers, **settings)
class AuxHandler(tornado.web.RequestHandler):
def get(self):
self.render("index.html")
class MainHandler(tornado.web.RequestHandler):
@asynchronous
@tornado.gen.coroutine
def get(self):
speed = int(self.get_argument("parameter"))
p=P()
if speed > 1:
p.startApp(speed)
if speed<1:
p.stopApp()
def main():
tornado.options.parse_command_line()
http_server = tornado.httpserver.HTTPServer(Application())
http_server.listen(options.port)
tornado.ioloop.IOLoop.instance().start()
if __name__ == "__main__":
main()
和p.py
@tornado.gen.coroutine
def startApp(self,speed):
x= yield print(speed)
while True:
yield x
在控制檯我收到此:
12
[I 160516 12:47:19 web:1946] 304 GET /action?parameter=12 (::1) 0.00ms
13
[I 160516 12:47:19 web:1946] 304 GET /action?parameter=13 (::1) 15.60ms
14
[E 160516 12:47:19 concurrent:336] Future <tornado.concurrent.Future object at 0x02FAA7D0> exception was never retrieved: Traceback (most recent call last):
File "C:\Users\home\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tornado\gen.py", line 1014, in run
yielded = self.gen.throw(*exc_info)
File "E:\work\python\Example2\p.py", line 11, in startApp
x= yield print(speed)
File "C:\Users\home\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tornado\gen.py", line 1008, in run
value = future.result()
File "C:\Users\home\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tornado\concurrent.py", line 232, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
File "C:\Users\home\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tornado\gen.py", line 1090, in handle_yield
self.future = convert_yielded(yielded)
File "C:\Users\home\AppData\Local\Programs\Python\Python35-32\lib\functools.py", line 743, in wrapper
return dispatch(args[0].__class__)(*args, **kw)
File "C:\Users\home\AppData\Local\Programs\Python\Python35-32\lib\site-packages\tornado\gen.py", line 1222, in convert_yielded
raise BadYieldError("yielded unknown object %r" % (yielded,))
tornado.gen.BadYieldError: yielded unknown object None
我不不知道如何處理這個問題「產生了未知的問題目標無「錯誤或者我的方法是否正確。任何想法都會非常有幫助。
您想獲得'打印()',它返回'None' – kwarunek
,當我在瀏覽器中移動滑塊時,它會被髮送的值速度打印()。如果我沒有收益(在p.py中),將永遠打印這個值(速度),但對於收益率,對於第一個值,不會收到任何錯誤,但過了一段時間後我會收到錯誤。 –