Created
March 27, 2021 15:29
-
-
Save leveryd/55adf1303fa7e528cc446d4e41526604 to your computer and use it in GitHub Desktop.
测试GIL
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 | |
n = 100000000 | |
def CountDown(n): | |
while n > 0: | |
n -= 1 | |
def test1(): | |
CountDown(n) | |
def test2(): | |
t1 = Thread(target=CountDown, args=[n // 2]) | |
t2 = Thread(target=CountDown, args=[n // 2]) | |
t1.start() | |
t2.start() | |
t1.join() | |
t2.join() | |
if __name__ == "__main__": | |
test2() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment