This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Multiprocessing. Instance of the custom class is missing in subprocesses
Type: behavior Stage: resolved
Components: Versions: Python 3.8
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: cyberlis
Priority: normal Keywords:

Created on 2020-06-09 16:01 by cyberlis, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
main.py cyberlis, 2020-06-09 16:01
Messages (1)
msg371117 - (view) Author: cyberlis (cyberlis) Date: 2020-06-09 16:01
When I use python3.7 everything works correctly and every subprocess has its own `Hello` instance. When I use python3.8 subprocesses do not have an instance of `Hello` class.
Is this behavior correct? 

My code to reproduce an issue

```python
from concurrent.futures.process import ProcessPoolExecutor
from concurrent.futures import as_completed
class Hello:
    _instance = None
    def __init__(self):
        print("Creating instance of Hello ", self)
        Hello._instance = self
def worker():
    return Hello._instance
def main():
    hello = Hello()
    with ProcessPoolExecutor(max_workers=2) as pool:
        futures = []
        for _ in range(4):
            futures.append(pool.submit(worker))

        for future in as_completed(futures):
            print(future.result())
if __name__ == "__main__":
    main()
```

Output
```bash
pyenv local 3.7.6
python main.py

Creating instance of Hello  <__main__.Hello object at 0x102f48310>
<__main__.Hello object at 0x103587410>
<__main__.Hello object at 0x1035874d0>
<__main__.Hello object at 0x103587110>
<__main__.Hello object at 0x1035871d0>

pyenv local 3.8.1
python main.py

Creating instance of Hello  <__main__.Hello object at 0x102104d90>
None
None
None
None
```
History
Date User Action Args
2022-04-11 14:59:32adminsetgithub: 85101
2020-06-09 16:10:51cyberlissetstatus: open -> closed
stage: resolved
2020-06-09 16:01:55cyberliscreate