When to use threading and how many threads to use

后端 未结 3 1795
情话喂你
情话喂你 2021-01-15 09:06

I have a project for work. We had written a module and there as a #TODO to implement threading to improve the module. I\'m a fairly new python programmer and decided to take

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-15 09:48

    No, this is not a good place to use threads.

    Generally, you want to use threads where your code is IO-bound; that is, it spends a significant amount of time waiting on input or output. An example might be downloading data from a list of URLs in parallel; the code can start requesting the data from the next URL while still waiting for the previous one to return.

    That's not the case here; calculating primes is cpu-bound.

提交回复
热议问题