Teile 10 bis 12.
This commit is contained in:
20
teil12/pool3.py
Normal file
20
teil12/pool3.py
Normal file
@@ -0,0 +1,20 @@
|
||||
# Quelle: https://www.codesdope.com/blog/article/multiprocessing-using-pool-in-python/
|
||||
import time
|
||||
from multiprocessing import Pool
|
||||
|
||||
|
||||
def square(x):
|
||||
print(f"start process:{x}")
|
||||
square = x * x
|
||||
print(f"square {x}:{square}")
|
||||
time.sleep(1)
|
||||
print(f"end process:{x}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
starttime = time.time()
|
||||
pool = Pool()
|
||||
pool.map(square, range(0, 5))
|
||||
pool.close()
|
||||
endtime = time.time()
|
||||
print(f"Time taken {endtime-starttime} seconds")
|
Reference in New Issue
Block a user