mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
GH-91048: Add utils for capturing async call stack for asyncio programs and enable profiling (#124640)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com> Co-authored-by: Kumar Aditya <kumaraditya@python.org> Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com> Co-authored-by: Jacob Coffee <jacob@z7x.org> Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
parent
60a3a0dd6f
commit
188598851d
23 changed files with 2923 additions and 241 deletions
|
@ -222,6 +222,56 @@ class FrameAttrsTest(unittest.TestCase):
|
|||
with self.assertRaises(AttributeError):
|
||||
del f.f_lineno
|
||||
|
||||
def test_f_generator(self):
|
||||
# Test f_generator in different contexts.
|
||||
|
||||
def t0():
|
||||
def nested():
|
||||
frame = sys._getframe()
|
||||
return frame.f_generator
|
||||
|
||||
def gen():
|
||||
yield nested()
|
||||
|
||||
g = gen()
|
||||
try:
|
||||
return next(g)
|
||||
finally:
|
||||
g.close()
|
||||
|
||||
def t1():
|
||||
frame = sys._getframe()
|
||||
return frame.f_generator
|
||||
|
||||
def t2():
|
||||
frame = sys._getframe()
|
||||
yield frame.f_generator
|
||||
|
||||
async def t3():
|
||||
frame = sys._getframe()
|
||||
return frame.f_generator
|
||||
|
||||
# For regular functions f_generator is None
|
||||
self.assertIsNone(t0())
|
||||
self.assertIsNone(t1())
|
||||
|
||||
# For generators f_generator is equal to self
|
||||
g = t2()
|
||||
try:
|
||||
frame_g = next(g)
|
||||
self.assertIs(g, frame_g)
|
||||
finally:
|
||||
g.close()
|
||||
|
||||
# Ditto for coroutines
|
||||
c = t3()
|
||||
try:
|
||||
c.send(None)
|
||||
except StopIteration as ex:
|
||||
self.assertIs(ex.value, c)
|
||||
else:
|
||||
raise AssertionError('coroutine did not exit')
|
||||
|
||||
|
||||
class ReprTest(unittest.TestCase):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue