Last active
February 18, 2020 14:29
-
-
Save Franck1333/02b6dd77430ded6bcae1879c4fc74cb6 to your computer and use it in GitHub Desktop.
Multi-Processing #1
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
#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() |
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
#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