Skip to content

Instantly share code, notes, and snippets.

@swshan
Created June 30, 2017 02:25
Show Gist options
  • Save swshan/0f9d7196ac779632dffac6f12dd74982 to your computer and use it in GitHub Desktop.
Save swshan/0f9d7196ac779632dffac6f12dd74982 to your computer and use it in GitHub Desktop.
python练习 多线程
from threading import Thread
import time
a = 0
def th1():
global a
a = a + 1
##print 'a: ', a
def th2():
global a
a = a + 1
##print 'a: ', a
t1 = Thread(target = th2)
t2 = Thread(target = th1)
t1.start()
print a
t2.start()
print a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment