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.