0 votes
in Python by (23.1k points)
How Do You Monitor The Code Flow Of A Program In Python?

1 Answer

0 votes
by (30.4k points)
In Python, we can use the sys module’s settrace() method to setup trace hooks and monitor the functions inside a program.

You need to define a trace callback method and pass it to the settrace() function. The callback should specify three arguments as shown below.

import sys

def trace_calls(frame, event, arg):

    # The 'call' event occurs before a function gets executed.

    if event != 'call':


    # Next, inspect the frame data and print information.

    print 'Function name=%s, line num=%s' % (frame.f_code.co_name, frame.f_lineno)


def demo2():

    print 'in demo2()'

def demo1():

    print 'in demo1()'



Click here to read more about Python
Click here to read more about Insurance

Related questions

+2 votes
asked Jan 10, 2021 in Python by rajeshsharma (23.1k points)
0 votes
asked May 17, 2020 in Python by sharadyadav1986 (30.4k points)