[Twisted-Python] Running CPU bound function concurrently in twisted

Moshe Zadka moshez at zadka.club
Mon Jun 24 17:37:26 MDT 2019


On Mon, Jun 24, 2019, at 16:27, Chengi Liu wrote:
>  cpu_res *= yield *defer.*gatherResults*(cpus)

Remember: This will not block the reactor (Good!) but will still limit you to one CPU core (in general, some caveats, but true.) If you are CPU bound, this is woefully underutilizing modern CPU resources (again, some caveats here).

> if __name__ == '__main__':

In general, the best thing to do is to to use twisted.internet.task.react for main. This would also solve the other problem you point out below.

https://twistedmatrix.com/documents/current/api/twisted.internet.task.html#react has a good example.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20190624/f6f5b223/attachment-0002.html>


More information about the Twisted-Python mailing list