diff --git a/Objet/__pycache__/main.cpython-310.pyc b/Objet/__pycache__/main.cpython-310.pyc index 5cc024724307d9d45be4574c2b3f472aaa136ee6..d0b4158647e682823c630cad49ac967424325081 100644 Binary files a/Objet/__pycache__/main.cpython-310.pyc and b/Objet/__pycache__/main.cpython-310.pyc differ diff --git a/Objet/__pycache__/menu.cpython-310.pyc b/Objet/__pycache__/menu.cpython-310.pyc index 995153ef28663e9975adb7abe4c3546fa8d2f720..83015087dea9d2d6546eccdd7ddb7b9648a3198e 100644 Binary files a/Objet/__pycache__/menu.cpython-310.pyc and b/Objet/__pycache__/menu.cpython-310.pyc differ diff --git a/Objet/__pycache__/trajectory.cpython-310.pyc b/Objet/__pycache__/trajectory.cpython-310.pyc index 35ca0cd65d6446c011005698b7cdd58aba4f8d3a..4f22c7283a097c3f0f0c0ab9fec80bb9bac23711 100644 Binary files a/Objet/__pycache__/trajectory.cpython-310.pyc and b/Objet/__pycache__/trajectory.cpython-310.pyc differ diff --git a/Objet/__pycache__/ui.cpython-310.pyc b/Objet/__pycache__/ui.cpython-310.pyc index 403d169a1c35e1a378410a8362e2153cfbedd86a..64e48af625d2e8ce57e84cb50d9d8a511d05fcf1 100644 Binary files a/Objet/__pycache__/ui.cpython-310.pyc and b/Objet/__pycache__/ui.cpython-310.pyc differ diff --git a/multithreading.py b/multithreading.py index a9d20f607ae682ac7803283aa489529e81e3177a..5d2d61e3ca7f74ba0ac19c355be5cb3fbcdc78db 100644 --- a/multithreading.py +++ b/multithreading.py @@ -1,29 +1,39 @@ import time import threading -# Fonction simulant une tâche lourde (ex: traitement d'image, calculs intensifs) -def tache_lourde(): +# Fonction qui effectue une partie du travail +def tache_lourde(part_debut, part_fin, resultat, index): somme = 0 - for _ in range(10**7): # Boucle qui prend un certain temps + for i in range(part_debut, part_fin): somme += 1 - return somme + resultat[index] = somme # Stocker le résultat pour éviter la concurrence + +# Paramètres +N = 10**7 # Taille du travail total +THREADS = 4 # Nombre de threads à utiliser # Exécution sans multithreading start = time.time() -for _ in range(4): # Exécuter 4 tâches séquentiellement - tache_lourde() +somme_total = sum(range(N)) # Exécution en une seule fois end = time.time() print(f"Temps sans multithreading: {end - start:.2f} secondes") # Exécution avec multithreading start = time.time() threads = [] -for _ in range(4): # Lancer 4 threads en parallèle - thread = threading.Thread(target=tache_lourde) +resultats = [0] * THREADS # Stocker les résultats des threads +portion = N // THREADS # Taille de la charge par thread + +for i in range(THREADS): + debut = i * portion + fin = N if i == THREADS - 1 else (i + 1) * portion + thread = threading.Thread(target=tache_lourde, args=(debut, fin, resultats, i)) threads.append(thread) thread.start() for thread in threads: - thread.join() # Attendre que tous les threads finissent + thread.join() # Attendre la fin de tous les threads + +somme_total_thread = sum(resultats) # Fusionner les résultats end = time.time() print(f"Temps avec multithreading: {end - start:.2f} secondes") diff --git a/test_chargement.py b/test_chargement.py index a7ed873ba88da90e8dc3376948511c0402c98810..c8908f807ce64f211255ad6af876089c5a8cc93b 100644 --- a/test_chargement.py +++ b/test_chargement.py @@ -1,9 +1,11 @@ import time +import threading +import os +import sys from tkinter import Tk, Label from PIL import Image, ImageTk # Installer Pillow si nécessaire : pip install pillow -# Lancer ton programme principal ici - +# --- Création du Splash Screen --- splash = Tk() splash.overrideredirect(True) # Enlever la barre de titre @@ -22,30 +24,30 @@ splash.geometry(f"{img_width}x{img_height}+{x_pos}+{y_pos}") # Afficher l'image label = Label(splash, image=photo) label.pack() +splash.update() # Mise à jour de l'affichage -# Garder le splash pendant le chargement -splash.update() - -# Pour éviter que le programme ne se ferme instantanément - - - -import os -import sys +# --- Fonction pour charger le menu principal --- +def charger_menu(): + global splash + base_dir = os.path.dirname(os.path.abspath(__file__)) + dossier_path = os.path.join(base_dir, 'Objet') + sys.path.append(dossier_path) + import menu # Importer ici pour éviter les blocages + temps = time.time() + + a = menu.App() # Chargement du menu + splash.destroy() # Fermer le splash après le chargement -# Fermer le splash et ouvrir le menu principal -base_dir = os.path.dirname(os.path.abspath(__file__)) + tmp = time.time() + print(f"Temps d'exécution : {-(temps - tmp):.6f} secondes") -dossier_path = os.path.join(base_dir,'Objet') -sys.path.append(dossier_path) + a.mainloop() # Lancer l'application principale + a.destroy() -import menu -temps = time.time() -a = menu.App() -splash.destroy() -tmp = time.time() -a.mainloop() +# --- Lancer le chargement en arrière-plan --- +thread = threading.Thread(target=charger_menu) +thread.start() -tot = temps - tmp -print(f"Temps d'exécution : {-tot:.6f} secondes") \ No newline at end of file +# --- Affichage du splash screen pendant le chargement --- +splash.mainloop() diff --git a/test_multithrading_logo.py b/test_multithrading_logo.py index f027b1417b66c1fb30e73dc3d471326e3914c591..57a1d5a06b8925cd523c943bd79d64bc3ecae4f9 100644 --- a/test_multithrading_logo.py +++ b/test_multithrading_logo.py @@ -43,15 +43,15 @@ def load_main_program(): base_dir = os.path.dirname(os.path.abspath(__file__)) - dossier_path = os.path.join(base_dir,'Code_objets') + dossier_path = os.path.join(base_dir,'Objet') sys.path.append(dossier_path) - import Menu + import menu # Lancer le programme principal ici - a = Menu.App() + a = menu.App() a.mainloop() # Démarrer le splash screen dans un thread