Jump to content

Python: Difference between revisions

6 bytes added ,  11 December 2020
Line 338: Line 338:
executor = ThreadPoolExecutor(max_workers=2 * os.cpu_count())
executor = ThreadPoolExecutor(max_workers=2 * os.cpu_count())
thread_lock = threading.Lock()
thread_lock = threading.Lock()
sum = 0
total = 0


def do_something(a, b):
def do_something(a, b):
   with thread_lock:
   with thread_lock:
     sum += a + b
     total += a + b
   return sum
   return total


futures = []
futures = []