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.
--- /dev/null
+#!/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]))