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

KeyError: sub.py #340

Closed
nedbat opened this issue Nov 16, 2014 · 8 comments
Closed

KeyError: sub.py #340

nedbat opened this issue Nov 16, 2014 · 8 comments
Labels
bug Something isn't working

Comments

@nedbat
Copy link
Owner

nedbat commented Nov 16, 2014

Originally reported by Buck Evan (Bitbucket: bukzor, GitHub: bukzor)


This reproduces when using the ubuntu 2.7 from precise forward.

ERROR: test_subprocess_with_pth_files (tests.test_process.ProcessStartupTest)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/buck/trees/mine/coverage.py/tests/test_process.py", line 673, in test_subprocess_with_pth_files
    self.assertEqual(data.summary()['sub.py'], 2)
KeyError: 'sub.py'

You can reproduce the scenario with:

mkdir $VIRTUALENV/local
ln -s $VIRTUALENV/lib $VIRTUALENV/local/lib

The essential cause is that site.py is seeing and executing subcover.py twice because of the symlink, first for local/lib/ then for lib/.

MAKEPATH: ('/home/buck/venv/coverage.py/local/lib/python2.7/site-packages',)
ADDPACKAGE: subcover.pth
MAKEPATH: ('/home/buck/venv/coverage.py/lib/python2.7/site-packages',)
ADDPACKAGE: subcover.pth

I don't quite follow the part in between, but the result is that only the data from the first trace persists, meaning we don't get the data we want. Presumably the trace of sub.py is written first, then the earlier trace data written on top of it.

The essential problem is that if a single process calls process_startup() twice, data is lost.
Worse, data generated by the second call is clobbered by data from the first.

I believe the fix would be to make coverage process_startup() idempotent.
Failing that, ensuring a last-one-wins behavior would also produce desirable behavior in this case.

@nedbat: How would you go about solving this problem?

(Most of this information copied from an older ticket centered on another topic: issue #337)


@nedbat
Copy link
Owner Author

nedbat commented Nov 16, 2014

Original comment by Buck Evan (Bitbucket: bukzor, GitHub: bukzor)


I've said this elsewhere, but not noted it here:

This problem stems from a hackitty virtualenv workaround to a poorly-written ubuntu patchset.

The problematic bit of the ubuntu patch is gone in the newest ubuntu (trusty), but the venv workaround remains, causing this issue.

@nedbat
Copy link
Owner Author

nedbat commented Nov 17, 2014

Original comment by Buck Evan (Bitbucket: bukzor, GitHub: bukzor)


This causes the "unexpected third case" in the pending __main__-support branch.
Ugh.

@nedbat
Copy link
Owner Author

nedbat commented Nov 23, 2014

What's the latest on this? Do you think it needs to be solved?

@nedbat
Copy link
Owner Author

nedbat commented Nov 23, 2014

Original comment by Buck Evan (Bitbucket: bukzor, GitHub: bukzor)


I've repeatedly run into this on ubuntu systems when using the stock python. It's quite annoying and extremely confusing.
The workaround is always rm -rf $VIRTUAL_ENV/local.

The idempotency/last-wins fixes proposed above would work, and might be simple enough to implement. I haven't looked.
I think the best fix would be to change virtualenv to fix their bug 118 a different way, not creating this local/ symlink.

@nedbat
Copy link
Owner Author

nedbat commented Jan 26, 2015

@bukzor Is this still happening for you? BTW, issue #353 also causes the "unexpected third case" assert, but for a different reason, if you want to chime in on what should happen there.

@nedbat
Copy link
Owner Author

nedbat commented Jan 26, 2015

Original comment by Buck Evan (Bitbucket: bukzor, GitHub: bukzor)


Yep, my situation unchanged since last post.

@nedbat
Copy link
Owner Author

nedbat commented Feb 1, 2015

@bukzor Thanks for the analysis, it was spot on. This is fixed in 9fd110c4bba0 (bb).

@nedbat nedbat closed this as completed Feb 1, 2015
@nedbat
Copy link
Owner Author

nedbat commented Feb 1, 2015

Original comment by Buck Evan (Bitbucket: bukzor, GitHub: bukzor)


Sweet! I'll check that it fixes my specific use case too. I expect so.

--phone is hard.

@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