Improved CTRL+C Exiting Speed (From 60s+ to around 15-30s)#2691
Open
nolanjparker wants to merge 3 commits intosherlock-project:masterfrom
Open
Improved CTRL+C Exiting Speed (From 60s+ to around 15-30s)#2691nolanjparker wants to merge 3 commits intosherlock-project:masterfrom
nolanjparker wants to merge 3 commits intosherlock-project:masterfrom
Conversation
rlone1366-dotcom
approved these changes
Apr 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The previous sherlock program took 60+ seconds (on my device) to exit with CTRL+C. I implemented a more effective and efficient way of handling CTRL+C that reduced the exiting time to around 15-30 seconds.
Solution
sherlock.py previously caught a SIGINT signal and exited gracefully with sys.exit(0) to handle CTRL+C. This method was slow because sys.exit(0) waited for all current and queued worker threads making I/O calls to finish or timeout. Instead, to exit more efficiently, I caught a KeyboardInterrupt exception and called session.shutdown(wait=False, cancel_futures=True) on each individual worker thread. This method is faster because it instructs each worker to terminate immediately after completing its current task (rather than finishing the thread) and cancels all threads in the queue. This drastically reduced the amount of time spent waiting on threads after pressing CTRL+C, allowing the program to exit much more quickly yet still gracefully.
Testing
Using a python virtual environment with WSL, I:
Type of Change