Skip to content

Instantly share code, notes, and snippets.

@clchiou
Created March 18, 2015 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clchiou/084b52ace48fbebe3bcc to your computer and use it in GitHub Desktop.
Save clchiou/084b52ace48fbebe3bcc to your computer and use it in GitHub Desktop.
Exit immediately after KeyboardInterrupt
#!/usr/bin/env python3
import time
import concurrent.futures.thread
from concurrent.futures import ThreadPoolExecutor, as_completed
with ThreadPoolExecutor(1) as executor:
fs = [executor.submit(time.sleep, 10)]
try:
for f in as_completed(fs):
f.result()
except KeyboardInterrupt:
executor._threads.clear()
concurrent.futures.thread._threads_queues.clear()
@leadscloud
Copy link

not work ctrl c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment