Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabled coverage CTracer may rise from the dead #436

Closed
nedbat opened this issue Oct 21, 2015 · 5 comments
Closed

Disabled coverage CTracer may rise from the dead #436

nedbat opened this issue Oct 21, 2015 · 5 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Oct 21, 2015

Originally reported by David MacIver (Bitbucket: david_maciver_, GitHub: Unknown)


The following code causes an issue for me where I have changed away from the coverage tracer to a tracer of my own devising, but the coverage CTracer mysteriously reappears.

import sys


def tracer(frame, event, arg):
    return tracer


def begin():
    sys.settrace(tracer)


def collect():
    t = sys.gettrace()
    assert t is tracer, t


def test_unsets_trace():
    begin()
    collect()


if __name__ == '__main__':
    test_unsets_trace()

Running the above code under 'python -m coverage run test_coverage_unset_trace.py' (or whatever you call the file) under Python 3.4.3 or 3.5.0 with coverage 4.0.1 produces the following error for me:

Traceback (most recent call last):
  File "test_coverage_regression.py", line 23, in <module>
    test_unsets_trace()
  File "test_coverage_regression.py", line 19, in test_unsets_trace
    collect()
  File "test_coverage_regression.py", line 14, in collect
    assert t is tracer, t
AssertionError: <coverage.CTracer object at 0x7fbdfa585a40>

Note: I do not see this issue on Coverage 4.0.0, or on Python 2.7 running 4.0.1. This seems to be specifically 4.0.1 and Python 3 together that cause the problem.

I originally believed this to be related to the fix for https://bitbucket.org/ned/coveragepy/issues/397/stopping-and-resuming-coverage-with, but I can't see why the tracer object would be running via settrace at this point rather than C level tracing, so this might be a red herring.

If I run this with --timid I get the "trace function changed" warning but do not see this problem.


@nedbat
Copy link
Owner Author

nedbat commented Nov 1, 2015

@david_maciver_ OK, it's easy for these experiments to skitter around. I see the same results on 2.7 and 3.5:

#!shell

$ python --version
Python 2.7.10
$ pip install coverage==4.0
Collecting coverage==4.0
  Using cached coverage-4.0-cp27-none-macosx_10_10_x86_64.whl
Installing collected packages: coverage
Successfully installed coverage-4.0
$ coverage run bug436.py
$ pip install coverage==4.0.1
Collecting coverage==4.0.1
  Using cached coverage-4.0.1-cp27-none-macosx_10_10_x86_64.whl
Installing collected packages: coverage
  Found existing installation: coverage 4.0
    Uninstalling coverage-4.0:
      Successfully uninstalled coverage-4.0
Successfully installed coverage-4.0.1
$ coverage run bug436.py
Traceback (most recent call last):
  File "bug436.py", line 23, in <module>
    test_unsets_trace()
  File "bug436.py", line 19, in test_unsets_trace
    collect()
  File "bug436.py", line 14, in collect
    assert t is tracer, t
AssertionError: <coverage.CTracer object at 0x108a8d3c8>
#!shell
$ python --version
Python 3.5.0
$ pip install coverage==4.0
Collecting coverage==4.0
  Using cached coverage-4.0-cp35-cp35m-macosx_10_10_x86_64.whl
Installing collected packages: coverage
Successfully installed coverage-4.0
$ coverage run bug436.py
$ pip install coverage==4.0.1
Collecting coverage==4.0.1
  Using cached coverage-4.0.1-cp35-cp35m-macosx_10_10_x86_64.whl
Installing collected packages: coverage
  Found existing installation: coverage 4.0
    Uninstalling coverage-4.0:
      Successfully uninstalled coverage-4.0
Successfully installed coverage-4.0.1
$ coverage run bug436.py
Traceback (most recent call last):
  File "bug436.py", line 23, in <module>
    test_unsets_trace()
  File "bug436.py", line 19, in test_unsets_trace
    collect()
  File "bug436.py", line 14, in collect
    assert t is tracer, t
AssertionError: <coverage.CTracer object at 0x101d700e8>

@nedbat
Copy link
Owner Author

nedbat commented Nov 1, 2015

Original comment by David MacIver (Bitbucket: david_maciver_, GitHub: Unknown)


The "Trace function changed" message is something I've only ever seen when running with the pure tracer. Is your 3.5 build not using CTracer for some reason?

Interesting that you see it on 2.7 though! I'm pretty sure I didn't, but I might have screwed up.

@nedbat
Copy link
Owner Author

nedbat commented Nov 1, 2015

Original comment by David MacIver (Bitbucket: david_maciver_, GitHub: Unknown)


It does make more sense that you'd see the same behaviour on 2.7 and 3.5 TBH. I'm going to assume I did something wrong that was causing me to not observe this behaviour on 2.7 - probably I had it running with the pure tracer, or the wind was in the wrong direction or something. :-)

@nedbat
Copy link
Owner Author

nedbat commented Nov 1, 2015

Yeah, looks like I had PyTracer on 3.5 earlier.

@nedbat
Copy link
Owner Author

nedbat commented Nov 2, 2015

Fixed in 3df0bf514505 (bb).

@nedbat nedbat closed this as completed Nov 2, 2015
@nedbat nedbat added major bug Something isn't working labels Jun 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant