[docs] [issue32017] profile.Profile() has no method enable()

bbayles report at bugs.python.org
Sun Feb 25 08:50:58 EST 2018


bbayles <bbayles at gmail.com> added the comment:

I'm afraid that profile.Profile and cProfile.Profile behave pretty differently, and there's not a good way to bring the methods from the C version to the Python version.

The example at [1] shows a cProfile.Profile object being instantiated and enabled. At this point the profiler is tracing execution - until the disable() method is called, any activity is recorded.

profile.Profile doesn't work this way. Creating a profile.Profile object doesn't cause activity to be recorded. It doesn't do anything until you call one of its run* methods.

This is because the C version uses PyEval_SetProfile ([2]) to take advantage of CPython's "low-level support for attaching profiling and execution tracing facilities" ([3]). I don't think we can do that from the Python version.

There is already a precedent for showing differences between cProfile.Profile and profile.Profile in the existing docs - see [4].


[1] https://docs.python.org/3/library/profile.html#profile.Profile
[2] https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Modules/_lsprof.c#L693
[3] https://docs.python.org/3/c-api/init.html#profiling-and-tracing
[4] https://docs.python.org/3/library/profile.html#using-a-custom-timer

----------
nosy: +bbayles

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32017>
_______________________________________


More information about the docs mailing list