Gestion de programmes en parallèles
Bonjour,
J'ai besoin de votre aide par rapport à la fonction thread, mon but étant de lancer un calcul et un timer en même temps.
Jusque là le programme se lance correctement mais maintenant je cherche à arrêter l'affichage de calcul quand le temps impartis est terminé.
Voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
import random
import sys
from threading import Thread
import time
######################################## FACILE ##############################################
class Afficheurfacile(Thread):
def _init_(self,calcul):
debut = Thread._init_(self)
self.calcul=calcul
def run(calcul):
while 1==1:
a = random.randint(0,30)
b = random.randint(0,30)
Signe=random.randint(1,2)
if Signe==1:
resu1=a-b
print a,'-',b,'='
resu2=input()
if resu1==resu2:
print 'bravo'
elif resu2!=resu1:
print 'dommage'
if Signe==2:
resu1=a+b
print a,'+',b,'='
resu2=input()
if resu1==resu2:
print 'bravo'
elif resu2!=resu1:
print 'dommage'
##################################################################################################
########################################## TIMER ###########################################
class Timer(Thread):
def run (timer):
i=5
while i!=0:
i=(i-1)
time.sleep (1)
if i==0:
print 'fini'
##############################################################################################
# Création des threads
thread_1=Afficheurfacile()
thread_4=Timer()
# Lancement des threads
thread_4.start()
thread_1.start()
# Attend que les threads se terminent
thread_1.join
thread_4.join |
Merci pour votre aide.