Skip to content

Instantly share code, notes, and snippets.

@leveryd
Created March 27, 2021 15:29
Show Gist options
  • Save leveryd/55adf1303fa7e528cc446d4e41526604 to your computer and use it in GitHub Desktop.
Save leveryd/55adf1303fa7e528cc446d4e41526604 to your computer and use it in GitHub Desktop.
测试GIL
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