classification
Title: Tracing not disabled in generator when the system trace function returns None.
Type: behavior Stage:
Components: Interpreter Core Versions: Python 3.4
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: nedbat, pitrou, serhiy.storchaka, xdegaye
Priority: normal Keywords:

Created on 2013-12-21 13:55 by xdegaye, last changed 2013-12-21 14:21 by vstinner.

Files
File name Uploaded Description Edit
tracer.py xdegaye, 2013-12-21 13:55
Messages (2)
msg206734 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2013-12-21 13:55
The sys.settrace documentation states:
  The trace function is invoked (with event set to 'call') whenever a new local scope is entered;
  it should return a reference to a local trace function to be used that scope, or None if the scope shouldn’t be traced.

But when tracing a generator, 'line' events may be traced even though tracing has been disabled by
returning None at the 'call' event. Run the attached tracer.py with 0 as argument and see that
tracing does not stop as it should when count is 1:
$ python tracer.py 0
call gen with count 0
line
line
return
call gen with count 1
returning None: the scope shouldn’t be traced
line
return

However, when tracer.py is run with 1 as argument, tracing is (correctly) disabled when count is 1
and 2. This problem is closely related to issue 11992.
The dispatch_call() method of Bdb in the bdb module is broken when the frame is a generator and the
previous command is next, until or return (and when this problem is fixed).
msg206738 - (view) Author: Xavier de Gaye (xdegaye) * (Python triager) Date: 2013-12-21 14:06
A patch is proposed in issue 20041.
History
Date User Action Args
2013-12-21 14:21:32vstinnersetnosy: + pitrou, serhiy.storchaka
2013-12-21 14:21:22vstinnersetnosy: + nedbat
2013-12-21 14:06:19xdegayesetmessages: + msg206738
2013-12-21 13:55:53xdegayecreate