From: W. Trevor King Date: Wed, 17 Apr 2013 16:15:49 +0000 (-0400) Subject: grab-cores.py: Use threading.Thread to call spam.busy X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=adf80bfc06cff100019c94d7be9c938b9110060c;p=cpython-extension.git grab-cores.py: Use threading.Thread to call spam.busy Usually Python threads can only use one core at a time due to the Python global interpreter lock. This script allows us to see if dropping the GIL with Py_BEGIN_ALLOW_THREADS allows us to use multiple cores simultaneously. --- diff --git a/grab-cores.py b/grab-cores.py new file mode 100755 index 0000000..0815443 --- /dev/null +++ b/grab-cores.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python + +import threading + +import spam + + +def grab_cores(threads=1, count=int(1e9)): + _threads = [] + for i in range(threads): + thread = threading.Thread(target=spam.busy, args=(count,)) + _threads.append(thread) + thread.start() + for thread in _threads: + thread.join() + + +if __name__ == '__main__': + import sys + + grab_cores(threads=int(sys.argv[1]))