Skip to content

Instantly share code, notes, and snippets.

@ryantuck
Created April 23, 2025 19:19
Show Gist options
  • Save ryantuck/6fc0fae0c7c9b8e4cbf8a7f0c944ed72 to your computer and use it in GitHub Desktop.
Save ryantuck/6fc0fae0c7c9b8e4cbf8a7f0c944ed72 to your computer and use it in GitHub Desktop.
threading_stuff.py
import random
import threading
import time
import concurrent.futures
def thread_fn(name):
x = random.randint(1, 3)
print(f"thread starting: {name} {x}")
time.sleep(x)
print(f"thread ending: {name} {x}")
def hello(name):
print(f'hello {name}')
if __name__ == "__main__":
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
executor.map(hello, range(10))
# print("Creating thread")
# y = threading.Thread(target=thread_fn, args=('asdf',), daemon=False)
# print("Running thread")
# y.start()
# print("Waiting for all threads")
# y.join()
# print("All done")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment