[Python-Dev] sys.settrace() in Python 2.3 vs. 2.4

Josiah Carlson jcarlson at uci.edu
Fri Jun 30 18:46:55 CEST 2006


I've previously asked on python-list, but have recieved no responses or
explanations.  Maybe someone here with a better memory can help, and I
apologize for asking a somewhat off-topic question about such an archaic
version of Python.

According to my reading of Python 2.3 docs, the call to goo() should
exit with a KeyboardInterrupt...

    import sys

    def goo():
        while 1:
            pass

    count = [100]
    def foo(frame, event, arg):
        count[0] -= 1
        if not count[0]:
            raise KeyboardInterrupt
        return foo

    sys.settrace(foo)

    goo()

In Python 2.3, the above call to goo() doesn't return.  Adding print
statements suggests that foo() is only called for each line executed in
goo() once.  It exits with a KeyboardInterrupt in 2.4, as expected,
where foo() is called for essentially every operaition performed. Does
anyone have an idea why this is the case? I've checked the release notes
for both 2.3 and 2.4 and found no discussion of trace functions in them
or in sourceforge (I could be entering the wrong search terms, of course).

Any pointers as to why there is a difference would be appreciated. Thank
you,
 - Josiah 



More information about the Python-Dev mailing list