[PYTHON] Multi-Prozess

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() #Ohne dies wird das Programm beendet, wenn worker2 endet.
Process-1: start
Process-1: 10
renamed worker2: start
renamed worker2: 10
renamed worker2: end
Process-1: end

Recommended Posts

Multi-Prozess
[Python] Über Multi-Prozess
Asynchron mit Python verarbeiten