Created
June 15, 2017 16:27
-
-
Save avyfain/4d3ffaf476cfb2341dec080047d54d62 to your computer and use it in GitHub Desktop.
A quick demo based on A. Jesse Jiryu Davis' PyCon 2017 "Grok the Gil" talk (https://www.youtube.com/watch?v=7SSYhuk5hmc)
This file contains 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
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