python- multiple threads share global variables

Threading Import 
Import Time

# define a variable
the nums = [. 11, 22 is]


DEF test1 (the nums):
nums.append (33 is)
Print ( '----------- in test1 --- NUM = {} '.format (the nums))


(DEF test2):
. Print (' ----------- in test2 NUM = {} --- 'the format (the nums))


DEF main ():
T1 = Threading .Thread (target = test1, args = (nums,)) # args pass parameters to use in the form of tuples
T2 of the threading.Thread = (target = test2)

t1.start ()
the time.sleep (. 1)

t2.start ( )
the time.sleep (. 1)

Print ( '----------- in the Thread main NUM = {} ---' the format (the nums.))


IF the __name__ == '__main__':
main ()

Guess you like

Origin www.cnblogs.com/fuyouqiang/p/11770320.html