I'm adapting an application that makes heavy use of generators to produce its results to provide a web.py web interface.
So far, I could wrap the call to the for-loop and the output-producing statements in a function and call that using cProfile.run()
or runctx()
. Conceptually:
def output():
for value in generator():
print(value)
cProfile.run('output()')
In web.py, I have to wrap it the following way, since I want to immediately produce output from the potentially long-running computation in each iteration step using yield
:
class index:
def GET(self):
for value in generator():
yield make_pretty_html(value)
Is there a way to profile all calls to the generator like in the first example when it's used like in the second one?