How do I add two integers together with Twisted?

后端 未结 3 1008
不思量自难忘°
不思量自难忘° 2021-01-30 04:16

I have two integers in my program; let\'s call them \"a\" and \"b\". I would like to add them together and get another integer as a result. These are

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-30 04:33

    Good question, and Twisted (or Python) should have a way to at least spawn "a + b" of to several cores (on my 8 core i7).

    Unfortunately the Python GIL prevents this from happening, meaning that you will have to wait, not only for the CPU bound task, but for one core doing the job, while the seven others core are doing nothing.

    Note: Maybe a better example would be "a() + b()", or even "fact(sqrt(a()**b())" etc. but the important fact is that above operation will lock one core and the GIL pretty much prevents Python for doing anything else during that operation, which could be several ms...

提交回复
热议问题