python multi-threading slower than serial?

前端 未结 3 1618
别跟我提以往
别跟我提以往 2020-11-30 11:18

I\'m trying to figure out multi-threading programming in python. Here\'s the simple task with which I want to compare serial and parallel speeds.

import thr         


        
3条回答
  •  悲哀的现实
    2020-11-30 12:11

    Python libraries that are written in C can obtain/release the Global Interpreter Lock (GIL) at will. Those that do not use Python objects can release the GIL so that other threads can get a look-in, however I believe that the math library uses Python Objects all the time, so effectively math.sin is serialised. Since locking/unlocking is an overhead, it is not unusual for Python threads to be slower than processes.

提交回复
热议问题