Python3 multithreading problem

how to make a multithreaded child thread execute one and then another

for T in range (len (answers)):

submitdata = answers[T]
thread = threading.Thread(target=self.threading_run,args=(T,));
thread.start()

import time, threading

balance = 0
lock = threading.Lock ()

def change_it (n):

-sharp 0:
global balance
balance = balance + n
balance = balance - n

def run_thread (n):

for i in range(100000):
    -sharp :
    lock.acquire()
    try:
        -sharp :
        change_it(n)
    finally:
        -sharp :
        lock.release()

T1 = threading.Thread (target=run_thread, args= (5,))
T2 = threading.Thread (target=run_thread, args= (8,))
t1.start ()
t2.start ()
t1.join ()
t2.join ()
print (balance)
Why locks report errors, and I can"t even use multithreading

lock = threading.Lock()

AttributeError: module "threading" has no attribute" Lock"

Mar.16,2021

implement thread Synchronize with threading.Lock locks.

< hr >

Please use for item of arr: to traverse another array, not for i in range (len (arr)):

.
Menu