[PYTHON] Parallélisation
import logging
import threading
import time
logging.basicConfig(level=logging.DEBUG, format='%(threadName)s: %(message)s')
def worker1():
logging.debug('start')
time.sleep(5)
logging.debug('end')
def worker2(x, y=1):
logging.debug('start')
logging.debug(x)
logging.debug(y)
time.sleep(2)
logging.debug('end')
if __name__ == '__main__':
t1 = threading.Thread(name='rename worker', target=worker1)
t1.setDaemon(True)
t2 = threading.Thread(target=worker2, args=(100,), kwargs={'y': 200})
t1.start()
t2.start()
print('started')
t1.join() #Attendez que worker1 termine le traitement. Sans cela, le programme se terminera à la fin du t2 précédent.
t2.join() #Vous n'êtes pas obligé de l'écrire car ce n'est pas un démon
production
rename worker: start
Thread-1: start
Thread-1: 100
Thread-1: 200
started
Thread-1: end
rename worker: end