cProfile.runctx()
cProfile.runctx() is a Python function in the CProfile Module category. Runs a command with explicit globals/locals under the profiler. The syntax is cProfile.runctx(command, globals, locals, filename=None). Returns: None. A typical example: cProfile.runctx("my_func()", {"my_func": my_func}, {}). A close sibling is cProfile.run(), which runs a Python statement under the profiler and prints statistics. A close sibling is cProfile.Profile.enable(), which starts collecting profiling data. A close sibling is cProfile.Profile.dump_stats(), which writes profiling data to a file (can be analyzed with pstats). More about this category: Performance profiler — run, runctx, Profile, enable, disable, dump_stats. Related CProfile Module entries: cProfile.run(), cProfile.Profile.enable(), cProfile.Profile.dump_stats(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try cProfile.runctx() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.