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

Appearance settings

Commit dd4bb05

Browse filesBrowse files
gh-110514: Add PY_THROW to sys.setprofile events (GH-110524)
1 parent 9f8282d commit dd4bb05
Copy full SHA for dd4bb05

File tree

3 files changed

+27
-1
lines changed
Filter options

3 files changed

+27
-1
lines changed

‎Lib/test/test_sys_setprofile.py

Copy file name to clipboardExpand all lines: Lib/test/test_sys_setprofile.py
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,25 @@ def g(p):
255255
(1, 'return', g_ident),
256256
])
257257

258+
def test_unfinished_generator(self):
259+
def f():
260+
for i in range(2):
261+
yield i
262+
def g(p):
263+
next(f())
264+
265+
f_ident = ident(f)
266+
g_ident = ident(g)
267+
self.check_events(g, [(1, 'call', g_ident),
268+
(2, 'call', f_ident),
269+
(2, 'return', f_ident),
270+
# once more; the generator is being garbage collected
271+
# and it will do a PY_THROW
272+
(2, 'call', f_ident),
273+
(2, 'return', f_ident),
274+
(1, 'return', g_ident),
275+
])
276+
258277
def test_stop_iteration(self):
259278
def f():
260279
for i in range(2):
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``PY_THROW`` to :func:`sys.setprofile` events

‎Python/legacy_tracing.c

Copy file name to clipboardExpand all lines: Python/legacy_tracing.c
+7-1Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,11 @@ _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
377377
PY_MONITORING_EVENT_PY_START, PY_MONITORING_EVENT_PY_RESUME)) {
378378
return -1;
379379
}
380+
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
381+
(vectorcallfunc)sys_profile_func3, PyTrace_CALL,
382+
PY_MONITORING_EVENT_PY_THROW, -1)) {
383+
return -1;
384+
}
380385
if (set_callbacks(PY_MONITORING_SYS_PROFILE_ID,
381386
(vectorcallfunc)sys_profile_func3, PyTrace_RETURN,
382387
PY_MONITORING_EVENT_PY_RETURN, PY_MONITORING_EVENT_PY_YIELD)) {
@@ -417,7 +422,8 @@ _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg)
417422
events =
418423
(1 << PY_MONITORING_EVENT_PY_START) | (1 << PY_MONITORING_EVENT_PY_RESUME) |
419424
(1 << PY_MONITORING_EVENT_PY_RETURN) | (1 << PY_MONITORING_EVENT_PY_YIELD) |
420-
(1 << PY_MONITORING_EVENT_CALL) | (1 << PY_MONITORING_EVENT_PY_UNWIND);
425+
(1 << PY_MONITORING_EVENT_CALL) | (1 << PY_MONITORING_EVENT_PY_UNWIND) |
426+
(1 << PY_MONITORING_EVENT_PY_THROW);
421427
}
422428
return _PyMonitoring_SetEvents(PY_MONITORING_SYS_PROFILE_ID, events);
423429
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.