cov.stop() stops coverage in the current thread, but fails to stop coverage in threads that were spawned since start().
this makes deploying coverage in long-running processes problematic, the intent is to selectively enable and disable coverage at runtime for testing.
perhaps trace function could detect a stopped coverage instance and destroy unregister itself in spawned thread context?
# SSCCE covbug.py import time import coverage import threading class T(threading.Thread): def run(self): time.sleep(0.2) if time: assert time # should not get covered c = coverage.coverage() c.start() T().start() time.sleep(0.1) c.stop() time.sleep(0.2) c.save()
On a related note, cov.start() does not cover threads that were already started. i understand that's a technical limitation, though perhaps a workaround could be provided?