Created
July 10, 2015 02:08
-
-
Save HeartSaVioR/34d90cdd6af906e72935 to your computer and use it in GitHub Desktop.
Python GIL with CPU intensive
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 | |
def repeatEvery(n, func, *args, **kwargs): | |
def and_again(): | |
func(*args, **kwargs) | |
t = threading.Timer(n, and_again) | |
t.daemon = True | |
t.start() | |
t = threading.Timer(n, and_again) | |
t.daemon = True | |
t.start() | |
def printLog(*args, **kwargs): | |
print "hello" | |
repeatEvery(0.5, printLog) | |
nums = xrange(100000000) | |
print -1 in nums | |
""" | |
When I run above code from OSX python 2.7.6 interpreter, it prints "hello" periodically. | |
But when "-1 in nums" is executed, it doesn't print anything about some secs, | |
and prints False, and continues printing "hello" | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment