[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-29 Thread eleven xiang


eleven xiang  added the comment:

I am not asking for your help to use python.
What I post here is to want to report a potential issue about multiprocessing 
module.

This issue is the default start method fork will not free the object, but other 
methods works normally.
When I change to use os.fork() APIs, it also could free object in child process.

So I think it is a bug that multiprocessing fork method doesn't free object in 
child process.

--

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-28 Thread eleven xiang


Change by eleven xiang :


--
resolution: not a bug -> 

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-28 Thread eleven xiang


eleven xiang  added the comment:

Below is the log:

// parent process call and increase it from 10 to 11.
process 71481, this = 0x7f4f271b5054, m_val = 10, A constructor called!!!
process 71481, this = 0x7f4f271b5054, m_val = 11, INC called!!!

// child process inherit with 11, and then also increase from 11 to 12
process 71482, this = 0x7f4f271b5054, m_val = 12, INC called!!!

// child process free it.
process 71482, this = 0x7f4f271b5054, m_val = 12, A destructor called!!!
// parent process free it.
process 71481, this = 0x7f4f271b5054, m_val = 11, A destructor called!!!

--

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-28 Thread eleven xiang


eleven xiang  added the comment:

I still have some questions about is, so re-open it.

You mean it is the fork principle, but if change the script to use os.fork(), 
the child process will inherit from parent, and also free it.

You could refer below change:


from ctypes import cdll
import multiprocessing as mp
import os

def foo():
handle = cdll.LoadLibrary("./test.so")
handle.IncA()

if __name__ == '__main__':
foo()
#p = mp.Process(target = foo, args = ())
#p.start()
#print(p.pid)
#p.join()

pid = os.fork()
if pid == 0:
foo()
else:
os.waitpid(pid, 0)

--
status: closed -> open

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-28 Thread eleven xiang


eleven xiang  added the comment:

update test platform

Ubuntu 16.04

--

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-28 Thread eleven xiang


eleven xiang  added the comment:

you could use below command to build test.so from test1.cpp

g++ test1.cpp -shared -fPIC --std=c++11 -o test.so

--

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-28 Thread eleven xiang


Change by eleven xiang :


Added file: https://bugs.python.org/file50308/test1.cpp

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45308] multiprocessing default fork child process will not free object, which is inherited from parent process

2021-09-28 Thread eleven xiang


New submission from eleven xiang :

Hi, 

Here I did an experiment, and detail as below
1. There is library, which has global object and has its class method
2. Use multiprocessing module to fork the child process, parent process call 
the global object's method first, and then child process called the global 
object method again to modify it
3. After that when script exit, parent will free the object, but child process 
will not free it.
4. if we change the start method to 'spawn', the child process will free it

--
components: Library (Lib)
files: test.py
messages: 402758
nosy: eleven.xiang
priority: normal
severity: normal
status: open
title: multiprocessing default fork child process will not free object, which 
is inherited from parent process
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file50307/test.py

___
Python tracker 
<https://bugs.python.org/issue45308>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com