From adf80bfc06cff100019c94d7be9c938b9110060c Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 17 Apr 2013 12:15:49 -0400 Subject: [PATCH] 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. --- grab-cores.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 grab-cores.py 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])) -- 2.26.2