You will need to do the splitting manually:
import threading def ThFun(start, stop): for item in range(start, stop): print item for n in range(0, 1000, 100): stop = n + 100 if n + 100 <= 1000 else 1000 threading.Thread(target = ThFun, args = (n, stop)).start()
This code uses multithreading, which means that everything will be executed within one Python process (i.e. only one Python interpreter will be launched).
Multiprocessing, discussed in another answer, means running some code in multiple Python interpreters (in multiple processes, not in threads). It can use all available CPU cores, so itβs useful when you focus on the speed of your code (print a ton of numbers until the terminal hates you!), And not just in parallel processing. one
1. multiprocessing.dummy turns out to be a wrapper around the threading module . multiprocessing and multiprocessing.dummy have the same interface, but the first module performs parallel processing using processes, and the second using threads.
Forcebru
source share