我发现在烧瓶的返回语句中链接几种方法可能存在错误。我想看看是否有人对如何解决这个问题有任何建议。
这是我的代码:
#!/usr/bin/env python
import flask
import time
from itertools import chain
from pygraphviz import AGraph
class TestClass(object):
def __init__(self):
G = ''
def worker(self):
a='1234'
b=a + '45\n'
yield b
time.sleep(3)
yield a
def worker2(self):
time.sleep(3)
c = '\n9876'
yield c
def graph(self):
G = AGraph(overlap='false')
tc = TestClass()
app = flask.Flask(__name__)
@app.route('/')
def test_method_get_stuff():
return flask.render_template('index.html')
@app.route('/', methods=['POST'])
def test_method_post_stuff():
def test_method_sub_function():
return chain(tc.worker(), tc.worker2(),tc.graph())
return flask.Response(test_method_sub_function(),mimetype= 'text/plain')
app.run(debug=True)
一旦请求一个帖子tc.worker()
,tc.worker2()
生成器就会正确返回,但一旦它尝试执行tc.graph()
它,就会出现以下错误。
* Running on http://127.0.0.1:5000/
* Restarting with reloader
127.0.0.1 - - [17/Aug/2014 18:23:17] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [17/Aug/2014 18:23:18] "POST / HTTP/1.1" 200 -
Debugging middleware caught exception in streamed response at a point where response headers were already sent.
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/werkzeug/wsgi.py", line 691, in __next__
return self._next()
File "/usr/lib/python2.7/site-packages/werkzeug/wrappers.py", line 81, in _iter_encoded
for item in iterable:
TypeError: 'NoneType' object is not iterable