From f0f1f9db2356b4f578574127739b0aaf7ebf22a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Madon?= <mael.madon@irit.fr> Date: Fri, 28 Jan 2022 21:07:02 +0100 Subject: [PATCH] =?UTF-8?q?campagne=20d'expe=20=C3=A0=20tester=20avec=20mu?= =?UTF-8?q?ltithread=20python?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- campaign1.py | 39 +++++++++++++++++++++++++++++---------- instance1.py | 2 +- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/campaign1.py b/campaign1.py index 5fbc957..73e267e 100644 --- a/campaign1.py +++ b/campaign1.py @@ -1,20 +1,39 @@ -from random import * +import random from time import * -import multiprocessing +import concurrent.futures from instance1 import start_instance # Prepare the start date samples -begin_trace = 1356994806 # according to original SWF header -jun1_unix_time, nov30_unix_time = mktime(strptime('Sun Jun 1 00:00:00 2014')), mktime(strptime('Sun Nov 30 23:59:59 2014')) -jun1, nov30 = (int) (jun1_unix_time - begin_trace), (int) (nov30_unix_time - begin_trace) +begin_trace = 1356994806 # according to original SWF header +jun1_unix_time, nov30_unix_time = mktime(strptime( + 'Sun Jun 1 00:00:00 2014')), mktime(strptime('Sun Nov 30 23:59:59 2014')) +jun1, nov30 = (int)(jun1_unix_time - + begin_trace), (int)(nov30_unix_time - begin_trace) random.seed(1997) -instances = [] -for i in range(2): - start_date = randint(jun1, nov30 - 72 * 3600) - instane = multiprocessing.Process(target=start_instance, args=) +nb_expe = 2 + + +def print_two(a, b): + print(a, b) + sleep(3) + print("hello") + return 0 + + +start_dates = [random.randint(jun1, nov30 - 72 * 3600) + for _ in range(nb_expe)] + +with concurrent.futures.ProcessPoolExecutor() as executor: + + instances = [executor.submit(start_instance, i, start_dates[i]) + for i in range(nb_expe)] + + for instance in concurrent.futures.as_completed(instances): + print(instance.result()) + # For every start date -# Call the one_instance file with this date \ No newline at end of file +# Call the one_instance file with this date diff --git a/instance1.py b/instance1.py index cc3fb94..0b0a4bc 100755 --- a/instance1.py +++ b/instance1.py @@ -99,7 +99,7 @@ def start_instance(expe_num, start_date): ###### Output data treatment ###### # Produce the utilisation viz? - + return 0 def main(): parser = argparse.ArgumentParser( -- GitLab