@@ -1084,13 +1084,38 @@ always available.
1084
1084
Set the system's profile function, which allows you to implement a Python source
1085
1085
code profiler in Python. See chapter :ref: `profile ` for more information on the
1086
1086
Python profiler. The system's profile function is called similarly to the
1087
- system's trace function (see :func: `settrace `), but it isn't called for each
1088
- executed line of code (only on call and return, but the return event is reported
1089
- even when an exception has been set). The function is thread-specific, but
1090
- there is no way for the profiler to know about context switches between threads,
1091
- so it does not make sense to use this in the presence of multiple threads. Also,
1087
+ system's trace function (see :func: `settrace `), but it is called with different events,
1088
+ for example it isn't called for each executed line of code (only on call and return,
1089
+ but the return event is reported even when an exception has been set). The function is
1090
+ thread-specific, but there is no way for the profiler to know about context switches between
1091
+ threads, so it does not make sense to use this in the presence of multiple threads. Also,
1092
1092
its return value is not used, so it can simply return ``None ``.
1093
1093
1094
+ Profile functions should have three arguments: *frame *, *event *, and
1095
+ *arg *. *frame * is the current stack frame. *event * is a string: ``'call' ``,
1096
+ ``'return' ``, ``'c_call' ``, ``'c_return' ``, or ``'c_exception' ``. *arg * depends
1097
+ on the event type.
1098
+
1099
+ The events have the following meaning:
1100
+
1101
+ ``'call' ``
1102
+ A function is called (or some other code block entered). The
1103
+ profile function is called; *arg * is ``None ``.
1104
+
1105
+ ``'return' ``
1106
+ A function (or other code block) is about to return. The profile
1107
+ function is called; *arg * is the value that will be returned, or ``None ``
1108
+ if the event is caused by an exception being raised.
1109
+
1110
+ ``'c_call' ``
1111
+ A C function is about to be called. This may be an extension function or
1112
+ a built-in. *arg * is the C function object.
1113
+
1114
+ ``'c_return' ``
1115
+ A C function has returned. *arg * is the C function object.
1116
+
1117
+ ``'c_exception' ``
1118
+ A C function has raised an exception. *arg * is the C function object.
1094
1119
1095
1120
.. function :: setrecursionlimit(limit)
1096
1121
@@ -1137,8 +1162,8 @@ always available.
1137
1162
1138
1163
Trace functions should have three arguments: *frame *, *event *, and
1139
1164
*arg *. *frame * is the current stack frame. *event * is a string: ``'call' ``,
1140
- ``'line' ``, ``'return' ``, ``'exception' ``, `` 'c_call' ``, ``'c_return ' ``, or
1141
- `` 'c_exception' ``, `` 'opcode' ``. * arg * depends on the event type.
1165
+ ``'line' ``, ``'return' ``, ``'exception' `` or ``'opcode ' ``. * arg * depends on
1166
+ the event type.
1142
1167
1143
1168
The trace function is invoked (with *event * set to ``'call' ``) whenever a new
1144
1169
local scope is entered; it should return a reference to a local trace
@@ -1175,16 +1200,6 @@ always available.
1175
1200
tuple ``(exception, value, traceback) ``; the return value specifies the
1176
1201
new local trace function.
1177
1202
1178
- ``'c_call' ``
1179
- A C function is about to be called. This may be an extension function or
1180
- a built-in. *arg * is the C function object.
1181
-
1182
- ``'c_return' ``
1183
- A C function has returned. *arg * is the C function object.
1184
-
1185
- ``'c_exception' ``
1186
- A C function has raised an exception. *arg * is the C function object.
1187
-
1188
1203
``'opcode' ``
1189
1204
The interpreter is about to execute a new opcode (see :mod: `dis ` for
1190
1205
opcode details). The local trace function is called; *arg * is
0 commit comments