Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcea9d4e

Browse files
GH-106152: Add PY_THROW event to cProfile (GH-106161)
1 parent7b2d94d commitcea9d4e

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

‎Lib/test/test_cprofile.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,26 @@ def test_second_profiler(self):
6666
self.assertRaises(ValueError,pr2.enable)
6767
pr.disable()
6868

69+
deftest_throw(self):
70+
"""
71+
gh-106152
72+
generator.throw() should trigger a call in cProfile
73+
In the any() call below, there should be two entries for the generator:
74+
* one for the call to __next__ which gets a True and terminates any
75+
* one when the generator is garbage collected which will effectively
76+
do a throw.
77+
"""
78+
pr=self.profilerclass()
79+
pr.enable()
80+
any(a==1forain (1,2))
81+
pr.disable()
82+
pr.create_stats()
83+
84+
forfunc, (cc,nc,_,_,_)inpr.stats.items():
85+
iffunc[2]=="<genexpr>":
86+
self.assertEqual(cc,2)
87+
self.assertEqual(nc,2)
88+
6989

7090
classTestCommandLine(unittest.TestCase):
7191
deftest_sort(self):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added PY_THROW event hook for:mod:`cProfile` for generators

‎Modules/_lsprof.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ static const struct {
678678
}callback_table[]= {
679679
{PY_MONITORING_EVENT_PY_START,"_pystart_callback"},
680680
{PY_MONITORING_EVENT_PY_RESUME,"_pystart_callback"},
681+
{PY_MONITORING_EVENT_PY_THROW,"_pystart_callback"},
681682
{PY_MONITORING_EVENT_PY_RETURN,"_pyreturn_callback"},
682683
{PY_MONITORING_EVENT_PY_YIELD,"_pyreturn_callback"},
683684
{PY_MONITORING_EVENT_PY_UNWIND,"_pyreturn_callback"},

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp