Due to the GIL, I thought that a multi-threaded python process can only have one thread running at a time, so CPU usage cannot exceed 100 percent.
But I found that the code below can take up 950% of the processor utilization at the top.
import threading import time def f(): while 1: pass for i in range(10): t = threading.Thread(target=f) t.setDaemon(True) t.start() time.sleep(60)
This is not such a question as Python interpreters use up to 130% of my processor. How is this possible? . In this question, the OP said that he was doing intensive load testing of I / O , which could release the GIL. But in my program there is no I / O operation.
Tests run on CPython 2.6.6.
, , 950%. , (avg), , , , .
- () , ( ). , , , runnable ( ).
- , . ( , ).
, , thread-, , . , , python , . , : 200%. , , 100%.
def f(): x=1 while 1: y=x*2