Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save HeartSaVioR/34d90cdd6af906e72935 to your computer and use it in GitHub Desktop.
Save HeartSaVioR/34d90cdd6af906e72935 to your computer and use it in GitHub Desktop.
Python GIL with CPU intensive
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