web3-starter-py/Concurrence_examples/unsafe_thread_example.py
2020-03-03 23:24:17 -08:00

22 lines
No EOL
340 B
Python

#!/usr/bin/env python3
import time
import threading
counter = 0
threads = []
def count():
global counter
for _ in range(100):
counter += 1
for _ in range(100):
thread = threading.Thread(target=count)
thread.start()
threads.append(thread)
for thread in threads:
thread.join()
print(f"Count: {counter}")