Blog categories

Comments

[Python] Multiprocess Pool ID 확인

[Python] Multiprocess Pool ID 확인

from multiprocessing import Pool
import multiprocessing

def f(x):
    current = multiprocessing.current_process()
    id = current.__dict__["_identity"]
    print("{}".format(id[-1]))
    return x * x

if __name__ == '__main__':
    with Pool(2) as p:
        print(p.map(f, range(6)))

current process 가 가지고 있는 정보는 아래와 같다.

from multiprocessing import Pool
import multiprocessing

def f(x):
    current = multiprocessing.current_process()
    print('running: {}'.format(current.__dict__))
    return x * x

if __name__ == '__main__':
    with Pool(2) as p:
        print(p.map(f, range(6)))
running: {'_identity': (1,), '_config': {'authkey': b'(생략)', 'semprefix': '/mp', 'daemon': True}, '_parent_pid': 15516, '_popen': None, '_target': <function worker at 0x0000027F7F9AF0D0>, '_args': (<multiprocessing.queues.SimpleQueue object at 0x0000027F7F9925C0>, <multiprocessing.queues.SimpleQueue object at 0x0000027F7F9C39B0>, None, (), None, True), '_kwargs': {}, '_name': 'SpawnPoolWorker-1'}
running: {'_identity': (1,), '_config': {'authkey': b'(생략)', 'semprefix': '/mp', 'daemon': True}, '_parent_pid': 15516, '_popen': None, '_target': <function worker at 0x0000027F7F9AF0D0>, '_args': (<multiprocessing.queues.SimpleQueue object at 0x0000027F7F9925C0>, <multiprocessing.queues.SimpleQueue object at 0x0000027F7F9C39B0>, None, (), None, True), '_kwargs': {}, '_name': 'SpawnPoolWorker-1'}
running: {'_identity': (2,), '_config': {'authkey': b'(생략)', 'semprefix': '/mp', 'daemon': True}, '_parent_pid': 15516, '_popen': None, '_target': <function worker at 0x000001C7E31EF0D0>, '_args': (<multiprocessing.queues.SimpleQueue object at 0x000001C7E31D2978>, <multiprocessing.queues.SimpleQueue object at 0x000001C7E3203A20>, None, (), None, True), '_kwargs': {}, '_name': 'SpawnPoolWorker-2'}
running: {'_identity': (1,), '_config': {'authkey': b'(생략)', 'semprefix': '/mp', 'daemon': True}, '_parent_pid': 15516, '_popen': None, '_target': <function worker at 0x0000027F7F9AF0D0>, '_args': (<multiprocessing.queues.SimpleQueue object at 0x0000027F7F9925C0>, <multiprocessing.queues.SimpleQueue object at 0x0000027F7F9C39B0>, None, (), None, True), '_kwargs': {}, '_name': 'SpawnPoolWorker-1'}
running: {'_identity': (2,), '_config': {'authkey': b'(생략)', 'semprefix': '/mp', 'daemon': True}, '_parent_pid': 15516, '_popen': None, '_target': <function worker at 0x000001C7E31EF0D0>, '_args': (<multiprocessing.queues.SimpleQueue object at 0x000001C7E31D2978>, <multiprocessing.queues.SimpleQueue object at 0x000001C7E3203A20>, None, (), None, True), '_kwargs': {}, '_name': 'SpawnPoolWorker-2'}
running: {'_identity': (1,), '_config': {'authkey': b'(생략)', 'semprefix': '/mp', 'daemon': True}, '_parent_pid': 15516, '_popen': None, '_target': <function worker at 0x0000027F7F9AF0D0>, '_args': (<multiprocessing.queues.SimpleQueue object at 0x0000027F7F9925C0>, <multiprocessing.queues.SimpleQueue object at 0x0000027F7F9C39B0>, None, (), None, True), '_kwargs': {}, '_name': 'SpawnPoolWorker-1'}
[0, 1, 4, 9, 16, 25]

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다

div#stuning-header .dfd-stuning-header-bg-container {background-image: url(https://tech.sangron.com/wp-content/uploads/sites/2/2018/02/python_wallpaper_background.jpg);background-color: #3f3f3f;background-size: cover;background-position: top center;background-attachment: initial;background-repeat: no-repeat;}#stuning-header div.page-title-inner {min-height: 350px;}