フラスコの return ステートメントで複数のメソッドをチェーンすることで、バグの可能性を見つけています。この問題を回避する方法について何か提案があるかどうかを知りたいと思いました。
これが私のコードです:
#!/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