Executed lines reported as missing in threads
See original GitHub issueOriginally reported by k3it (Bitbucket: k3it, GitHub: k3it)
I apologize for a cross post from http://stackoverflow.com/q/43991865/1653558 but it looks like this is a better place for the report
I’m getting some low coverage numbers on script with threads activated with a run() method. It seems that the coverage module is unable to keep track of all hits. Here is the code that demonstrates the problem. Running it should produce 100% coverage, but I’m getting 71.
#!python
from threading import Thread
class MyNestedThread(Thread):
def run(self):
print("hello from the nested thread!")
class MyThread(Thread):
def run(self):
print("Hello from thread")
t = MyNestedThread()
t.start()
return
if __name__ == '__main__':
for i in range(3):
t = MyThread()
t.start()
#!python
Hello from thread
hello from the nested thread!
Hello from thread
Hello from thread
hello from the nested thread!
hello from the nested thread!
Name Stmts Miss Cover
----------------------------
foo.py 14 4 71%
re-running ‘coverage run foo.py’ sometimes gives a different %, and even 100% on occasion.
Issue Analytics
- State:
- Created 6 years ago
- Comments:41 (22 by maintainers)
Top Results From Across the Web
Basic python threading is not working. What am I missing in this?
In the line that initializes the thread, you are actually executing the function instead of passing its reference to the thread.
Read more >Command line usage — Coverage.py 6.4.4 documentation
Here's a sample report. Lines are highlighted green for executed, red for missing, and gray for excluded. The counts at the top of...
Read more >Manage concurrent threads - Python Module of the Week
Purpose: Builds on the thread module to more easily manage several threads of execution. Available In: 1.5.2 and later ...
Read more >An Intro to Threading in Python
In this intermediate-level tutorial, you'll learn how to use threading in your Python programs. You'll see how to create threads, how to coordinate...
Read more >View threads in the Parallel Stacks window - Visual Studio ...
In Threads view, the stack frame and call path of the current thread are highlighted in blue. The current location of the thread...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Threads won’t be measured unless you specify them as part of your concurrency setting:
Hi, I found this thread when looking for a solution to a problem I wrote up here.
I am also having trouble measuring coverage in threads. I do
join()
my threads as suggested in this thread so that does not seem to be the problem. You can see the link above for additional info on the environment. I’d be grateful for any help!