8000 [Feature] Clean up temporary files generated by gcov tool when exception occurs. by kenchung285 · Pull Request #1106 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[Feature] Clean up temporary files generated by gcov tool when exception occurs. #1106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 6, 2025

Conversation

kenchung285
Copy link
Contributor

Related Issue

Please see #1096 for more information

Tests

Due to #1105 errors in the latest main branch, this commits are manually tested on gcovr 8.3. The manual test includes multi-thread situations.

Close Issue

Closes #1096

@Spacetown
Copy link
Member

Thanks for working on this but I think there is an easier way to I need to check it after my vacation on my computer.

Copy link
Member
@Spacetown Spacetown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do not need the temporary_files isn't needed and we should better handle it in the worker thread.
Please update the changeling and add yourself to the list of contributors.

Comment on lines 856 to 857
if filepath in temporary_files:
temporary_files.remove(filepath)
Copy link
Member
@Spacetown Spacetown Jun 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This for loop should be split. In line 794 after calling select_gcov_files_from_stdout we should delete the files list(all_gcov_files - active_gcov_files) and at the end in a finally block we should delete all files in active_gcov_files unless options.gcov_keep is set or we are not done.
In that case we do not need the temporary_files. Correct me if I'm wrong here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this way, I think we are going to delete active_gcov_files in each thread when exception occurs.

(The following part is partially wrong, please refer to the latest comment)
However, according to my understanding, an exception will only be captured once in a multi-thread process, that is to say, only one thread that capture the exception will go to the finally block and delete those active_gcov_files generated by the thread and keep those active_gcov_files generated by other threads remain.

Therefore, in my implementation, I don't handle the exception in each worker thread, and only capture it in the main thread in line 95. In this way, we can ensure only the main thread will capture the exception and delete those active_gcov_files through temporary_files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, here's some update about the exception in a python multi-threading process after my survey and manual test with some python script

A signal ( KeyboardInterrupt is SIGINT, one of the signal to process ) will only be sent to the main thread in a python multi-threading process. See python official document on signal vs thread for more information.

Therefore, if we handle these exceptions in worker threads, those finally block won't be triggered if an keyboardInterrupt occurs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On keyboard interrupt it's fine for me to left the file because the user wants to abort (same as sending SIG_TERM or SIG_KILL).
We should delete the files as soon and as local as possible. Also if someone wants to keep the files why shall they be deleted if an interrupt occurs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. But is there a possible situation that someone wants to keep the files when they interrupt on their own? Those files are automatically removed by worker threads in just few seconds even if user not interrupt the files.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also if someone wants to keep the files why shall they be deleted if an interrupt occurs

I want to know more about this consideration. If all files are removed at the end of the process, users are not easily to know what files will be kept when an interrupt occurs, then in what situation, users may want to keep the files?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the user sets options.gcov_keep he wants to keep the files. If we remove all not used files direct after creation the user can be sure that the present files are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Then if the use doesn't set options.gcov_keep and the user abort gcovr, should we remove active_gcov_file ?

Take myself, as a user of gcovr, for example, I sometimes aborted gcovr and before my next run, I need to remove temporary files manually. So I recommend to remove these active_gcov_file if user doestn't set options.gcov_keep

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The active files are removed after the processing of the current gcda file. Why do you need to remove the files before the next run?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed on your branch. Now on keyboard interrupt the pool is drained and all the files are removed depending on the option --gcov-keep. Please can you check this on your site?

@kenchung285 kenchung285 requested a review from Spacetown June 24, 2025 16:16
@Spacetown
Copy link
Member

@kenchung285 Can you reply to the comments?

@kenchung285
Copy link
Contributor Author

Hi @Spacetown, I have replied to those comments and ping you for review.
But now I find those comments marked as Pending by github.
Do you know how to make these comments ready or just not labeled as Pending?

@kenchung285
Copy link
Contributor Author
kenchung285 commented Jun 25, 2025

I've resubmit those comments and they seems great now. PTAL, thanks!

@Spacetown
Copy link
Member

Hi @Spacetown, I have replied to those comments and ping you for review. But now I find those comments marked as Pending by github. Do you know how to make these comments ready or just not labeled as Pending?

You pressed the "Start review" button and in that case the comments are pending until you finish the review.

@Spacetown
Copy link
Member

Ple 8000 ase add yourself to the list of contributors and update the CHANGELOG.

Copy link
codacy-production bot commented Jul 2, 2025

Coverage summary from Codacy

See diff coverage on Codacy

Coverage variation Diff coverage
-0.04% (target: -1.00%) 88.24% (target: 97.00%)
Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (2c39b58) 4602 4475 97.24%
Head commit (ffc1492) 4611 (+9) 4482 (+7) 97.20% (-0.04%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#1106) 17 15 88.24%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

See your quality gate settings    Change summary preferences

Spacetown and others added 2 commits July 2, 2025 14:54
Signed-off-by: Cheng-Yeh Chung <kenchung285@gmail.com>
@kenchung285
Copy link
Contributor Author

Please add yourself to the list of contributors and update the CHANGELOG.

Sorry for late reply. I've update the CHANGELOG and I've been added to the list of authors in #1075

@Spacetown
Copy link
Member

Does it work for you?

Copy link
Member
@Spacetown Spacetown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGFM

@kenchung285
Copy link
Contributor Author

Does it work for you?

LGTM. But I would like to have some manual tests this weekend, is that okay with you?

@kenchung285
Copy link
Contributor Author

Does it work for you?

LGTM. But I would like to have some manual tests this weekend, is that okay with you?

@Spacetown I've test this PR with my small testing project. It looks good!

@Spacetown Spacetown merged commit 1831119 into gcovr:main Jul 6, 2025
64 of 66 checks passed
Spacetown added a commit to Spacetown/gcovr that referenced this pull request Jul 6, 2025
gcovr#1106)

- Forcefully stop on keyboard interrupts.

Signed-off-by: Cheng-Yeh Chung <kenchung285@gmail.com>
Co-authored-by: Spacetown <40258682+spacetown@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] temporary files are not removed when error occurs
2 participants
0