Skip to content

Instantly share code, notes, and snippets.

@Franck1333
Last active February 18, 2020 14:29
Show Gist options
  • Save Franck1333/02b6dd77430ded6bcae1879c4fc74cb6 to your computer and use it in GitHub Desktop.
Save Franck1333/02b6dd77430ded6bcae1879c4fc74cb6 to your computer and use it in GitHub Desktop.
Multi-Processing #1
#Aides: https://tutorialedge.net/python/python-multiprocessing-tutorial/
from multiprocessing import Process #Declaration de l'Utilisation de la LIB MultiProcessing
import random #Declaration de l'Utilisation de la LIB random
def rand_num(): #Cette fonction permet de creer un ou plusieur Nombre aleatoirement pour l'exemple
num = random.random()
print(num) #Affichage des Nombre aleatoirement generer
if __name__ == "__main__":
processes = [Process(target=rand_num, args=()) for x in range(4)] #Creation d'un process et integration de la fonction
for p in processes: #Demarrage du multiprocessing de la fonction
p.start() #avec .start()
for p in processes: #Fin de course du multiprocessing
p.join() #avec .join()
#https://www.journaldev.com/15631/python-multiprocessing-example
import multiprocessing
print("Number of cpu : ", multiprocessing.cpu_count())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment