Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from concurrent.futures import ThreadPoolExecutor
- import threading
- import time, random
- class myClass():
- val = 0
- class Main():
- def start(self):
- executor = ThreadPoolExecutor(max_workers=10)
- for i in range(10):
- future = executor.submit(self.worker, str(i))
- def worker(self, i):
- self.local = threading.local()
- self.local.t = myClass()
- time.sleep(random.randint(0, 3))
- self.local.t.val += 1
- print('#' + i, str(self.local.t)[1:-1], self.local.t.val)
- Main().start()
Advertisement
Add Comment
Please, Sign In to add comment