Open
Labels
3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-featureA feature request or enhancementA feature request or enhancement
Description
| BPO | 46934 |
|---|---|
| Nosy | @maggyero |
| PRs |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = None
closed_at = None
created_at = <Date 2022-03-05.22:19:15.660>
labels = ['type-feature', 'library', '3.11']
title = 'Started multiprocessing.Process instances are unserialisable'
updated_at = <Date 2022-03-05.23:19:58.658>
user = 'https://github.com/maggyero'bugs.python.org fields:
activity = <Date 2022-03-05.23:19:58.658>
actor = 'maggyero'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2022-03-05.22:19:15.660>
creator = 'maggyero'
dependencies = []
files = []
hgrepos = []
issue_num = 46934
keywords = ['patch']
message_count = 1.0
messages = ['414597']
nosy_count = 1.0
nosy_names = ['maggyero']
pr_nums = ['31701']
priority = 'normal'
resolution = None
stage = 'patch review'
status = 'open'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue46934'
versions = ['Python 3.11']Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-multiprocessingtype-featureA feature request or enhancementA feature request or enhancement
Projects
- StatusShow more project fieldsNo status
Activity
maggyero commentedon Mar 5, 2022
The Python program:
Its output:
In the function
Application.__init__, each callmultiprocessing.Process(target=self._worker)initializes amultiprocessing.Processinstance with the instance methodself._workeras itstargetargument.self._workeris bound toselfwhich has the instance attributeself._processes.In the function
Application.start, each callprocess.start()serialises thetargetargument and thereforeself._processes.self._processesis a list ofmultiprocessing.Processinstances, initially not started yet. The first callprocess.start()starts the firstmultiprocessing.Processinstance in that list without issue, but the second callprocess.start()fails.So a started
multiprocessing.Processinstance cannot be serialised.The root of the problem is that the
startmethod of amultiprocessing.Processinstance sets its_popeninstance attribute to amultiprocessing.popen_*.Popeninstance. The initialization of that instance performs these two steps (among others):For a
multiprocessing.popen_spawn_posix.Popeninstance, amultiprocessing.popen_spawn_win32.Popeninstance, or amultiprocessing.popen_forkserver.Popeninstance but not amultiprocessing.popen_fork.Popeninstance (i.e. for the start method'spawn'or the start method'forkserver'but not the start method'fork'), it serialises themultiprocessing.Processinstance for writing it to the end of the pipe used by the parent process to communicate with the child process so that the child process can execute therunmethod of themultiprocessing.Processinstance.It sets its
finalizerinstance attribute to amultiprocessing.util.Finalizeinstance which itself sets its_weakrefinstance attribute to aweakref.refinstance for closing at interpreter exit the ends of the pipes used by the parent process to communicate with the child process. In other words, it makes themultiprocessing.Processinstance hold a weak reference.Thus if a
multiprocessing.Processinstance holds a reference to a startedmultiprocessing.Processinstance then it holds a weak reference (point 2), so starting it will fail since it will serialise (point 1) the weak reference and weak references are not serialisable:A minimal Python program showing the serialisation issue:
[-]A started multiprocessing.Process instance cannot be serialised[/-][+]Started multiprocessing.Process instances are unserialisable[/+][-]A started multiprocessing.Process instance cannot be serialised[/-][+]Started multiprocessing.Process instances are unserialisable[/+]saurabh02 commentedon Apr 21, 2022
Up-voting this issue
arikon commentedon Mar 27, 2023
Do this bug have a workaround?
make examples support smp/spmd in python3.8+