Created
April 23, 2025 19:19
-
-
Save ryantuck/6fc0fae0c7c9b8e4cbf8a7f0c944ed72 to your computer and use it in GitHub Desktop.
threading_stuff.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
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