classification
Title: Multiprocessing does not work properly when using the trace module.
Type: behavior Stage:
Components: Windows Versions: Python 3.9
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: paul.moore, rls1004, steve.dower, tim.golden, zach.ware, تاشيرات مساند
Priority: normal Keywords:

Created on 2019-10-18 06:54 by rls1004, last changed 2019-10-18 11:46 by تاشيرات مساند.

Files
File name Uploaded Description Edit
test.py rls1004, 2019-10-18 06:54 test code
Messages (2)
msg354864 - (view) Author: minjeong kim (rls1004) Date: 2019-10-18 06:54
normal result :
$ python test.py
{'p1': 1, 'p2': 1, 'p3': 1, 'p4': 1}

run with tracing :
$ python -mtrace --trackcalls test.py
{}

It seems that the foo and save functions that multiprocess should call are not called.
msg354879 - (view) Author: تاشيرات مساند (تاشيرات مساند) Date: 2019-10-18 11:46
#!/usr/bin/env python
import multiprocessing, sys, trace
from functools import partial

num_list = ['p1', 'p2', 'p3', 'p4']

def foo(name):
    print(name+'\n')
    return name
def save(result, shared):
    print('a\n')
    shared.results[result] = 1

def mm():
    manager = multiprocessing.Manager()
    shared = manager.dict()
    shared.results = dict()

    clbk = partial(save, shared=shared)

    pool = multiprocessing.Pool(processes=2)
    serial_pool = multiprocessing.Pool(1)

    for name in num_list:
        serial_pool.apply_async(foo, args=[name], callback=clbk)

    pool.close()
    pool.join()

    print(shared.results)

mm()
History
Date User Action Args
2019-10-18 11:46:53تاشيرات مساندsetmessages: + msg354879
2019-10-18 11:46:34تاشيرات مساندsetnosy: + تاشيرات مساند
2019-10-18 11:46:09تاشيرات مساندsetnosy: + paul.moore, tim.golden, zach.ware, steve.dower

components: + Windows, - Library (Lib)
versions: + Python 3.9, - Python 2.7, Python 3.5, Python 3.6
2019-10-18 06:54:41rls1004create