What's the point of multithreading in Python if the GIL exists?

后端 未结 2 1508
长情又很酷
长情又很酷 2020-12-31 00:56

From what I understand, the GIL makes it impossible to have threads that harness a core each individually.

This is a basic question, but, what is then the point of

2条回答
  •  庸人自扰
    2020-12-31 01:23

    Strictly speeaking, CPython support multi-io-bound-thread + single-cpu-bound-thread

    io bound method: file.open, file.write, file.read, socket.send, socket.recv, etc. when python call these io function, it will release GIL and acquire GIL after io function return implicitly

    cpu bound method: arithmatic calculation, etc.

    c extension method: method must call PyEval_SaveThread & PyEval_RestoreThread explicitly to tell the python interpreter what you are doing

提交回复
热议问题