Skip to content

Instantly share code, notes, and snippets.

@ahmed-abdelazim
Last active July 3, 2020 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmed-abdelazim/140ae2296c48e616a663c5d394d84443 to your computer and use it in GitHub Desktop.
Save ahmed-abdelazim/140ae2296c48e616a663c5d394d84443 to your computer and use it in GitHub Desktop.
multiprocessing python example
import multiprocessing.pool
import time
def theout(i):
print(i)
time.sleep(1)
pool = multiprocessing.pool.Pool(processes=10)
pool.map(theout, range(100))
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()
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