-
Notifications
You must be signed in to change notification settings - Fork 107
Open
Description
Hi there,
Concurrency is great topic. I followed the code regarding threaded_visits.py. Authors argued that when I will run the file, I will get unexpected results. However, I am getting expected 10_000_000 value for thread_visits.
My hypothesis: There might be changes in threading standard library.
Looking for your reply!
from threading import Thread
thread_visits = 0
def visit_counter():
global thread_visits
for i in range(100_000):
# value = thread_visits
thread_visits += 1
if __name__ == "__main__":
thread_count = 100
threads = [
Thread(target=visit_counter)
for _ in range(thread_count)
]
for thread in threads:
thread.start()
for thread in threads:
thread.join()
print(f"{thread_count=}, {thread_visits=}")(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000
(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000
(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000
(my_bert) (base) sardor@Sardors-MacBook-Pro Concurrency % python3 thread_chaos.py
thread_count=100, thread_visits=10000000Metadata
Metadata
Assignees
Labels
No labels