Created
July 21, 2019 19:24
-
-
Save DavidMertz/70426a91b2b8efd67ebf813e105c1255 to your computer and use it in GitHub Desktop.
Python loops that might terminate
This file contains 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
(base) 530-tmp % python thread_kill.py | |
[1, 2, 3, 4, 5, 1] | |
[1, 2, 3, 4, 5, 1, 2] | |
[1, 2, 3, 4, 5, 1, 2, 3] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3] | |
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4, 5, 1, 2, 3, 4] |
This file contains 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
import threading | |
from time import sleep | |
items = [] | |
def killer(): | |
global items | |
sleep(0.00008) | |
for _ in range(1_000_000): | |
items[:] = [] | |
threading.Thread(target=killer).start() | |
items = [1,2,3,4,5] | |
for item in items: | |
items.append(item) | |
print(items, flush=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment