Created
June 30, 2017 02:25
-
-
Save swshan/0f9d7196ac779632dffac6f12dd74982 to your computer and use it in GitHub Desktop.
python练习 多线程
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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