Last active
July 3, 2020 15:38
-
-
Save ahmed-abdelazim/140ae2296c48e616a663c5d394d84443 to your computer and use it in GitHub Desktop.
multiprocessing python example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import multiprocessing.pool | |
import time | |
def theout(i): | |
print(i) | |
time.sleep(1) | |
pool = multiprocessing.pool.Pool(processes=10) | |
pool.map(theout, range(100)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from multiprocessing import Process | |
def process_file(): | |
print("Something") | |
p1 = Process(target=process_file) | |
p1.start() | |
p2 = Process(target=process_file) | |
p2.start() | |
p1.join() | |
p2.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
import time | |
i = 300 | |
def ThFun(start, stop): | |
for item in range(start, stop): | |
time.sleep(1) | |
print (item) | |
for n in range(0, i, 10): | |
stop = n + 10 if n + 10 <= i else i | |
threading.Thread(target = ThFun, args = (n, stop)).start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment