Coverage threading bug.

Issue #369 closed
Michael Forbes
created an issue

Consider the following test program:

import threading
initialised = threading.Event()
initialised.clear()

def run():
    initialised.set()

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

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

t.join()

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 threading_bug.py
nosetests --with-coverage --cover-package=threading_bug threading_bug.py

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 threading_bug.py

work and

coverage run -m threading_bug.py

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/cmdline.py", line 644, in main
    status = CoverageScript().command_line(argv)
  File ".../coverage/coveragepy/coverage/cmdline.py", line 413, in command_line
    self.do_run(options, args)
  File ".../coveragepy/coverage/cmdline.py", line 529, in do_run
    self.run_python_module(args[0], args)
  File ".../coveragepy/coverage/execfile.py", line 91, in run_python_module
    pathname, packagename = find_module(modulename)
  File ".../coveragepy/coverage/execfile.py", 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 threading_bug.py", which is not a correct way to invoke this file. It would be trying to run threading_bug/py.py, 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 threading_bug.py" ?

  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
    ------------------------------------------------
    __init__.py            0      0   100%
    threading_bug.py      11      1    91%   14
    ------------------------------------------------
    TOTAL                 11      1    91%
    $ nosetests --with-coverage --cover-package=threading_bug threading_bug.py
    
    Coverage.py 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>
        sys.exit(run_exit())
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/core.py", line 121, in __init__
        **extra_args)
      File "/usr/lib/python2.7/unittest/main.py", line 95, in __init__
        self.runTests()
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/core.py", line 207, in runTests
        result = self.testRunner.run(self.test)
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/core.py", line 66, in run
        result.printErrors()
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/result.py", line 110, in printErrors
        self.config.plugins.report(self.stream)
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/plugins/manager.py", line 99, in __call__
        return self.call(*arg, **kw)
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/plugins/manager.py", line 167, in simple
        result = meth(*arg, **kw)
      File "/home/loic/software/coveragepy/issue-425/v/local/lib/python2.7/site-packages/nose/plugins/cover.py", line 190, in report
        self.coverInstance.report(modules, file=stream)
      File "/home/loic/software/coveragepy/issue-425/coverage.py/coverage/control.py", line 975, in report
        return reporter.report(morfs, outfile=file)
      File "/home/loic/software/coveragepy/issue-425/coverage.py/coverage/summary.py", 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