Coverage threading bug.

Issue #369 closed
Michael Forbes created an issue

Consider the following test program:

import threading
initialised = threading.Event()

def run():

t = threading.Thread(target=run)
t.daemon = True

while not initialised.is_set():
    # processes hang here...
    pass    # Could do something like time.sleep(1) - same effect.


Starting with revision 2ff50c9162ce I observe the following behaviour: the following two commands hang as indicated above (nosetests version 1.3.6):

coverage run -m
nosetests --with-coverage --cover-package=threading_bug

but the following works

coverage run -m threading_bug

Prior to this revision

coverage run -m threading_bug
nosetests --with-coverage --cover-package=threading_bug

work and

coverage run -m

works but gives an error

Traceback (most recent call last):
  File ".../bin/coverage", line 9, in <module>
    load_entry_point('coverage==4.0a1', 'console_scripts', 'coverage')()
  File ".../coverage/coveragepy/coverage/", line 644, in main
    status = CoverageScript().command_line(argv)
  File ".../coverage/coveragepy/coverage/", line 413, in command_line
    self.do_run(options, args)
  File ".../coveragepy/coverage/", line 529, in do_run
    self.run_python_module(args[0], args)
  File ".../coveragepy/coverage/", line 91, in run_python_module
    pathname, packagename = find_module(modulename)
  File ".../coveragepy/coverage/", line 54, in find_module
    searchpath = package.__path__
AttributeError: 'module' object has no attribute '__path__'

Comments (5)

  1. Ned Batchelder repo owner

    Thanks for the exotic bug report! In your examples, you have "coverage run -m", which is not a correct way to invoke this file. It would be trying to run threading_bug/, which doesn't exist. It might be running it because it has to import threading_bug first, and your code is all at the top level of the file.

    Are you really running it as "coverage run -m" ?

  2. Michael Forbes reporter

    I was running it through nosetests which is where I had the problem. I tried to reproduce the behaviour using just coverage to ensure that it was not simply a nosebleed and was able to reproduce it this way. Perhaps nose is not calling coverage correctly?

  3. Loic Dachary

    Here is what I get with pyhon 2.7.12 and coverage from master f787b514c0ed

    $ coverage run --source=. -m threading_bug
    $ coverage report -m
    Name               Stmts   Miss  Cover   Missing
    ------------------------------------------------            0      0   100%      11      1    91%   14
    TOTAL                 11      1    91%
    $ nosetests --with-coverage --cover-package=threading_bug warning: Module threading_bug was never imported.
    Name    Stmts   Miss  Cover
    Traceback (most recent call last):
      File "/home/loic/software/coveragepy/issue-425/v/bin/nosetests", line 11, in <module>
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/", line 121, in __init__
      File "/usr/lib/python2.7/unittest/", line 95, in __init__
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/", line 207, in runTests
        result =
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/", line 66, in run
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/", line 110, in printErrors
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/plugins/", line 99, in __call__
        return*arg, **kw)
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/plugins/", line 167, in simple
        result = meth(*arg, **kw)
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/plugins/", line 190, in report, file=stream)
      File "/home/loic/software/coveragepy/issue-425/", line 975, in report
        return, outfile=file)
      File "/home/loic/software/coveragepy/issue-425/", line 155, in report
        raise CoverageException("No data to report.")
    coverage.misc.CoverageException: No data to report.
  4. Loic Dachary

    The error from nosetests seems to happen after the run completes which is (hopefully) an indication that it does not hang any more. Is it reasonable to assume the problem is not there any more ?

  5. Log in to comment