@@ -1005,13 +1005,38 @@ always available.
10051005 Set the system's profile function, which allows you to implement a Python source
10061006 code profiler in Python. See chapter :ref: `profile ` for more information on the
10071007 Python profiler. The system's profile function is called similarly to the
1008- system's trace function (see :func: `settrace `), but it isn't called for each
1009- executed line of code (only on call and return, but the return event is reported
1010- even when an exception has been set). The function is thread-specific, but
1011- there is no way for the profiler to know about context switches between threads,
1012- so it does not make sense to use this in the presence of multiple threads. Also,
1008+ system's trace function (see :func: `settrace `), but it is called with different events,
1009+ for example it isn't called for each executed line of code (only on call and return,
1010+ but the return event is reported even when an exception has been set). The function is
1011+ thread-specific, but there is no way for the profiler to know about context switches between
1012+ threads, so it does not make sense to use this in the presence of multiple threads. Also,
10131013 its return value is not used, so it can simply return ``None ``.
10141014
1015+ Profile functions should have three arguments: *frame *, *event *, and
1016+ *arg *. *frame * is the current stack frame. *event * is a string: ``'call' ``,
1017+ ``'return' ``, ``'c_call' ``, ``'c_return' ``, or ``'c_exception' ``. *arg * depends
1018+ on the event type.
1019+
1020+ The events have the following meaning:
1021+
1022+ ``'call' ``
1023+ A function is called (or some other code block entered). The
1024+ profile function is called; *arg * is ``None ``.
1025+
1026+ ``'return' ``
1027+ A function (or other code block) is about to return. The profile
1028+ function is called; *arg * is the value that will be returned, or ``None ``
1029+ if the event is caused by an exception being raised.
1030+
1031+ ``'c_call' ``
1032+ A C function is about to be called. This may be an extension function or
1033+ a built-in. *arg * is the C function object.
1034+
1035+ ``'c_return' ``
1036+ A C function has returned. *arg * is the C function object.
1037+
1038+ ``'c_exception' ``
1039+ A C function has raised an exception. *arg * is the C function object.
10151040
10161041.. function :: setrecursionlimit(limit)
10171042
@@ -1058,8 +1083,8 @@ always available.
10581083
10591084 Trace functions should have three arguments: *frame *, *event *, and
10601085 *arg *. *frame * is the current stack frame. *event * is a string: ``'call' ``,
1061- ``'line' ``, ``'return' ``, ``'exception' ``, `` 'c_call' ``, `` 'c_return' ``, or
1062- `` 'c_exception' ``. * arg * depends on the event type.
1086+ ``'line' ``, ``'return' `` or ``'exception' ``. * arg * depends on
1087+ the event type.
10631088
10641089 The trace function is invoked (with *event * set to ``'call' ``) whenever a new
10651090 local scope is entered; it should return a reference to a local trace
@@ -1094,16 +1119,6 @@ always available.
10941119 tuple ``(exception, value, traceback) ``; the return value specifies the
10951120 new local trace function.
10961121
1097- ``'c_call' ``
1098- A C function is about to be called. This may be an extension function or
1099- a built-in. *arg * is the C function object.
1100-
1101- ``'c_return' ``
1102- A C function has returned. *arg * is the C function object.
1103-
1104- ``'c_exception' ``
1105- A C function has raised an exception. *arg * is the C function object.
1106-
11071122 Note that as an exception is propagated down the chain of callers, an
11081123 ``'exception' `` event is generated at each level.
11091124
0 commit comments