[New-bugs-announce] [issue40929] Multiprocessing. Instance of the custom class is missing in subprocesses
cyberlis
report at bugs.python.org
Tue Jun 9 12:01:56 EDT 2020
New submission from cyberlis <cyberlis at rccraft.ru>:
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
```
----------
files: main.py
messages: 371117
nosy: cyberlis
priority: normal
severity: normal
status: open
title: Multiprocessing. Instance of the custom class is missing in subprocesses
type: behavior
versions: Python 3.8
Added file: https://bugs.python.org/file49223/main.py
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue40929>
_______________________________________
More information about the New-bugs-announce
mailing list