Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
A quick demo based on A. Jesse Jiryu Davis' PyCon 2017 "Grok the Gil" talk (https://www.youtube.com/watch?v=7SSYhuk5hmc)
import threading
n = 0
def foo():
global n
n += 1
def test(iterations):
global n
n = 0
threads = []
for i in range(iterations):
t = threading.Thread(target=foo)
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join()
print(n)
def main():
for iterations in (10**x for x in range(2, 6)):
raw_input("Let's try with {}".format(iterations))
for _ in range(10):
test(iterations)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment