It's all about Python2.7
I have next question:
from futures import ThreadPoolExecutor
def test():
while True:
i = 4
executor = ThreadPoolExecutor(max_workers=2)
executor.submit(test)
executor.submit(test)
So when I run such code on dualcore machine, I get both of cores get busy Why does it happens, shouldn't they execute using just half of resourses, because of GIL? I think they use some system calls and thats why executes in parallel, but I can't understand which part of code executes on system core.
here is disassabmled:
dis.dis(main)
Disassembly of test:
2 0 SETUP_LOOP 16 (to 19)
>> 3 LOAD_GLOBAL 0 (True)
6 POP_JUMP_IF_FALSE 18
3 9 LOAD_CONST 1 (4)
12 STORE_FAST 0 (i)
15 JUMP_ABSOLUTE 3
>> 18 POP_BLOCK
>> 19 LOAD_CONST 0 (None)
22 RETURN_VALUE
Also should be noted, that when I run ths code, I can't stop program by typing Ctr+C.
I think its happend because when I have 2 cores, and 3 threads (1 main and 2 threadpool) After typing Ctr+C interpreter execute check after each tick and though ThreadPool threads are cpu bound and have low priority main thread can't accuire GIL because on another core on of ThreadPool thread catch GIL faster
But in my understanding, sometime main thread should aquire GIL and stop program, but it not happend during 5 min.
Whats going wrong?