@@ -1084,13 +1084,38 @@ always available.
10841084 Set the system's profile function, which allows you to implement a Python source
10851085 code profiler in Python. See chapter :ref: `profile ` for more information on the
10861086 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,
10921092 its return value is not used, so it can simply return ``None ``.
10931093
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.
10941119
10951120.. function :: setrecursionlimit(limit)
10961121
@@ -1137,8 +1162,8 @@ always available.
11371162
11381163 Trace functions should have three arguments: *frame *, *event *, and
11391164 *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.
11421167
11431168 The trace function is invoked (with *event * set to ``'call' ``) whenever a new
11441169 local scope is entered; it should return a reference to a local trace
@@ -1175,16 +1200,6 @@ always available.
11751200 tuple ``(exception, value, traceback) ``; the return value specifies the
11761201 new local trace function.
11771202
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-
11881203 ``'opcode' ``
11891204 The interpreter is about to execute a new opcode (see :mod: `dis ` for
11901205 opcode details). The local trace function is called; *arg * is
0 commit comments