Skip to content

Instantly share code, notes, and snippets.

@bduggan
Created October 29, 2021 14:31
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 bduggan/22d700057f6a90fdcd75d5ea3a896f1e to your computer and use it in GitHub Desktop.
Save bduggan/22d700057f6a90fdcd75d5ea3a896f1e to your computer and use it in GitHub Desktop.
threads.py
#!/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()
@bduggan
Copy link
Author

bduggan commented Oct 29, 2021

python3 thread-ids.py|grep -c reusing
991
python3 thread-ids.py|grep -c new
9

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