Multi-processus
import logging
import multiprocessing
import time
logging.basicConfig(level=logging.DEBUG, format='%(processName)s: %(message)s')
def worker1(i):
logging.debug('start')
logging.debug(i)
time.sleep(5)
logging.debug('end')
def worker2(i):
logging.debug('start')
logging.debug(i)
logging.debug('end')
if __name__ == '__main__':
i = 10
t1 = multiprocessing.Process(target=worker1, args=(i,))
t1.daemon = True
t2 = multiprocessing.Process(name = 'renamed worker2', target=worker2, args=(i,))
t1.start()
t2.start()
t2.join()
t1.join() #Sans cela, le programme se terminera à la fin de worker2.
Process-1: start
Process-1: 10
renamed worker2: start
renamed worker2: 10
renamed worker2: end
Process-1: end