Closed Chenyu-dev353 closed 2 weeks ago
You have logging in your coverage management code. Can you show the output you are seeing? Also, are there new subprocesses spawned to handle requests?
After some debugs, I have updated my bootstrap file above, please check before see this.
I am not sure if I have missed some processes or something went wrong in Coverage.py settings, but I will still attach my logs here.
So for the step 4, 6, the logs are as below:
step 4: I started the application, make no request and collect the coverage by sending SIGUSR2 to all processes containing "Python" in its name:
2024-09-19 10:44:00,217 - INFO - exit signal handler for cov type: 1
2024-09-19 10:44:00,217 - INFO - stop cov
2024-09-19 10:44:00,217 - INFO - exit signal handler for cov type: 1
2024-09-19 10:44:00,217 - INFO - stop cov
2024-09-19 10:44:00,217 - INFO - stop cov success
2024-09-19 10:44:00,217 - INFO - save cov
2024-09-19 10:44:00,217 - INFO - stop cov success
2024-09-19 10:44:00,217 - INFO - save cov
2024-09-19 10:44:00,230 - INFO - save cov success
2024-09-19 10:44:00,230 - INFO - create new cov instance
2024-09-19 10:44:00,230 - INFO - save cov success
2024-09-19 10:44:00,230 - INFO - create new cov instance
2024-09-19 10:44:00,234 - INFO - new cov instance started successfully
2024-09-19 10:44:00,234 - INFO - new cov instance started successfully
And for step 6, I sent a request and collect again, the logs are:
2024-09-19 10:45:31,143 - INFO - exit signal handler for cov type: 2
2024-09-19 10:45:31,143 - INFO - stop cov
2024-09-19 10:45:31,143 - INFO - exit signal handler for cov type: 2
2024-09-19 10:45:31,143 - INFO - stop cov
2024-09-19 10:45:31,143 - INFO - stop cov success
2024-09-19 10:45:31,143 - INFO - save cov
2024-09-19 10:45:31,143 - INFO - stop cov success
2024-09-19 10:45:31,143 - INFO - save cov
2024-09-19 10:45:31,153 - INFO - save cov success
2024-09-19 10:45:31,153 - INFO - create new cov instance
2024-09-19 10:45:31,153 - INFO - save cov success
2024-09-19 10:45:31,153 - INFO - create new cov instance
2024-09-19 10:45:31,156 - INFO - new cov instance started successfully
2024-09-19 10:45:31,156 - INFO - new cov instance started successfully
Everything seems to be right but I still cannot collect the coverage, the result is still 0%
It seems that if I use the Flask's method app.run() with multiprocesses, I will not collect any coverage data.
I will appreciate it if you can maybe give us some hint about this problem, and i am not sure if there is some configuration error or it is just because there might be some bug in the version 5.3
You should read this: https://coverage.readthedocs.io/en/latest/subprocess.html
coverage 5.3 is unsupported and Python 2.7 is unsupported, but that might fix your problem.
The background of this issue is that I need to collect the coverage data of running Python project without interrupting the process. However I found that it always only shows the original coverage data for some constants, so I wrote a demo for this and found the same problem.
For some reason we have to use the shell file to create a new bootstrap.py file and start the application:
the code above is my bootstrap.py, where I started my Python project, and it also has one useful subfile(views.py) as below:
The coveragerc file is also attached here:
The version for Coverage.py and my Python version is 5.3 and 2.7 separately, and here is what i do:
coverage combine && coverage report && mv .coverage .coverage.before
(otherwise the original coverage data file will be covered by coverage combine but that's not that important)Please inform me if you have any idea of this problem, as our project is using Python 2.7 and cannot be updated to Python 3 temporarily, Thank you for your help