Message291957
This is a sub-problem of #9285, in #9285, we aim to provide cProfile and profile a context manager, this will need to add code like this:
def __enter__(self):
self.set_cmd('')
sys.setprofile(self.dispatcher)
return self
Unfortunately, when setting up profiler via `sys.setprofile`, it will immediately work on next line `return self`, which cause the assertion inside `trace_dispatch_return` claim this is a "Bad return".
Technically, `profile.Profile` can not go return upper than it's frame inside the frame stack. This behavior can be observed by this code:
def fib(n):
if n > 2:
return fib(n - 1) + fib(n - 2)
return n
def foo():
pr = profile.Profile()
# Profile was set in the `foo` frame, it can't get more upper than this
# that means, we can't return to global frame when this profile is set
sys.setprofile(pr.dispatcher)
fib(5)
# We didn't stop the profile here via sys.setprofile(None)
# So it will return 0xDEADBEAF to global frame and cause a bad return
return 0xDEADBEAF
foo()
Here this issue will provide the test of this behavior, then will make some modify in #9285 to prevent this situation when using profile as a context manager. |
|
Date |
User |
Action |
Args |
2017-04-20 09:36:32 | louielu | set | recipients:
+ louielu, ncoghlan |
2017-04-20 09:36:32 | louielu | set | messageid: <1492680992.58.0.5244415067.issue30113@psf.upfronthosting.co.za> |
2017-04-20 09:36:32 | louielu | link | issue30113 messages |
2017-04-20 09:36:32 | louielu | create | |
|