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

Change solution for issue#164 #245

nedbat opened this issue Jun 28, 2013 · 1 comment

Change solution for issue#164 #245

nedbat opened this issue Jun 28, 2013 · 1 comment
enhancement New feature or request


Copy link

nedbat commented Jun 28, 2013

Originally reported by Johan Olsen (Bitbucket: johanolsen, GitHub: Unknown)


I had the issue #164, and tried the fix for it. On some of my code however, this gave some errors at the end of the coverage run. It turns out that this is to my code defining its own cmp on classes derived from threading.Thread. I use this to be able to sort threads on my own. I use this test code:


import threading

class MyThread (threading.Thread):
    def __init__(self, num):
        self.num = num
    def run(self):
        print "Hello %s, %s" % (self.num, self.ident)
    def __cmp__(self, other):
        return cmp(self.num, other.num)

thr1 = MyThread(1)
thr2 = MyThread(2)

and get this printouts / traceback:

coverage run
Hello 1, 7028
 Hello 2, 6292
Traceback (most recent call last):
  File "C:\Python27\Scripts\", line 8, in <module>  
    load_entry_point('coverage==3.6', 'console_scripts', 'coverage')()  
  File "c:\Python27\lib\site-packages\coverage\", line 710, in main  
    status = CoverageScript().command_line(argv)
  File "c:\Python27\lib\site-packages\coverage\", line 429, in command_line
    self.do_execute(options, args)
  File "c:\Python27\lib\site-packages\coverage\", line 565, in do_execute
  File "c:\Python27\lib\site-packages\coverage\", line 374, in stop
  File "c:\Python27\lib\site-packages\coverage\", line 287, in stop
  File "c:\Python27\lib\site-packages\coverage\", line 299, in pause
  File "c:\Python27\lib\site-packages\coverage\", line 127, in stop
    if self.thread != threading.currentThread():
  File "", line 13, in __cmp__
    if self.num > other.num:
AttributeError: '_MainThread' object has no attribute 'num'

I suggest to replace
if self.thread != threading.currentThread():
if self.thread.ident != threading.currentThread().ident:
in, which I think will solve this problem.

Copy link
Owner Author

nedbat commented May 8, 2016

Applied in 7c56dc3b3338 (bb), though I suggest that your comparison function is buggy if it cannot be used on any thread.

@nedbat nedbat closed this as completed May 8, 2016
@nedbat nedbat added enhancement New feature or request and removed proposal labels Oct 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
enhancement New feature or request
None yet

No branches or pull requests

1 participant