Created
October 29, 2021 14:31
-
-
Save bduggan/22d700057f6a90fdcd75d5ea3a896f1e to your computer and use it in GitHub Desktop.
threads.py
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
#!/usr/bin/env python3 | |
import threading | |
seen = {} | |
def get_client(): | |
key = id(threading.current_thread()) | |
if seen.get(key): | |
print(f'reusing id {key}') | |
pass | |
else: | |
print(f'new id #{key}') | |
seen[key] = 1 | |
for i in range(0,1000): | |
th = threading.Thread(target=get_client) | |
th.start() | |
th.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
python3 thread-ids.py|grep -c reusing
991
python3 thread-ids.py|grep -c new
9