Issue 25726: [doc] sys.setprofile / sys.getprofile asymetry - Python tracker
Python Home About News Documentation Downloads Community Foundation Developer's Guide Issue Tracker Issues Search Random Issue Summaries Issues with patch Easy issues Stats User Administration User List Committer List Help Tracker Documentation Tracker Development Report Tracker Problem Issue25726 ➜ This issue tracker has been migrated to GitHub , and is currently read-only . For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on 2015-11-24 23:04 by stefan , last changed 2022-04-11 14:58 by admin . Messages (2) msg255301 - (view) Author: Stefan Seefeld (stefan) * Date: 2015-11-24 23:04 I'm using the `cProfile` module to profile my code. I tried to temporarily disable the profiler by using: prof = sys.getprofile() sys.setprofile(None) ... sys.setprofile(prof) resulting in an error. The reason is that with `cProfile`, `sys.getprofile` returns the profile object itself, which isn't suitable as argument for `sys.setprofile` (which expects a callable).
Notice that if I use the `profile` module instead of `cProfile`, the above works fine. msg260234 - (view) Author: Georg Brandl (georg.brandl) * Date: 2016-02-13 11:58 Ok, this is because internally, sys.setprofile (or to be exact, PyEval_SetProfile) sets two things: a C function, and a "profileobj", which is the argument to setprofile(). sys.setprofile sets the C function to the "profile_trampoline", which supports calling Python profile functions.
The profileobj is the Python profile function. The C profiler sets the C function to a different callback, and uses the profileobj for storing the reference to the Profiler object. sys.getprofile just returns the profileobj, which means that you can't save/restore the profiler state with the two functions when using cProfile. There is not much we can do here except for explicitly documenting this. History Date User Action Args 2022-04-11 14:58:24 admin set github: 69912 2021-12-07 15:35:18 iritkatriel set title: sys.setprofile / sys.getprofile asymetry -> [doc] sys.setprofile / sys.getprofile asymetry versions: + Python 3.9, Python 3.10, Python 3.11, - Python 3.4 2016-02-13 11:58:36 georg.brandl set nosy: + docs@python messages: + msg260234 assignee: docs@python components: + Documentation 2016-02-13 03:54:12 ned.deily set nosy: + georg.brandl 2015-11-24 23:04:27 stefan create Supported by The Python Software Foundation , Powered by Roundup Copyright © 1990-2022, Python Software Foundation Legal Statements