Guest User

Untitled

a guest
Mar 7th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. from concurrent.futures import ThreadPoolExecutor
  2. import threading
  3. import time, random
  4.  
  5. class myClass():
  6.     val = 0
  7.  
  8. class Main():
  9.  
  10.     def start(self):
  11.         executor = ThreadPoolExecutor(max_workers=10)
  12.  
  13.         for i in range(10):
  14.             future = executor.submit(self.worker, str(i))
  15.  
  16.     def worker(self, i):
  17.  
  18.         self.local = threading.local()
  19.         self.local.t = myClass()
  20.         time.sleep(random.randint(0, 3))
  21.         self.local.t.val += 1
  22.  
  23.         print('#' + i, str(self.local.t)[1:-1], self.local.t.val)
  24.  
  25. Main().start()
Advertisement
Add Comment
Please, Sign In to add comment