New submission from Alessandro Molina <[email protected]>:
When a new `multiprocessing.managers.BaseManager` instance is made, the client
used to connect is not stable across the life of the object.
A very quick example to show that is
```
from unittest.mock import Mock
from multiprocessing.managers import SyncManager, listener_client
listener_client["faked"] = listener_client["xmlrpclib"]
sm = SyncManager(serializer="faked")
```
As expected the manager is created with the XmlClient
```
>>> print(sm._Client.__name__)
XmlClient
```
but in reality, if the "faked" serializer is changed in any way
```
listener_client["faked"] = (None, Mock(side_effect=RuntimeError("BROKEN")))
```
When trying to connect, we will unexpectedly connect with whatever it is the
serializer registered at the time of connection instead of the one bound to the
SyncManager instance
```
>>> sm.connect()
Traceback (most recent call last):
File "/home/amol/wrk/cpython/prova.py", line 17, in <module>
sm.connect()
File "/home/amol/wrk/cpython/Lib/multiprocessing/managers.py", line 521, in
connect
conn = Client(self._address, authkey=self._authkey)
...
File "/home/amol/wrk/cpython/Lib/unittest/mock.py", line 1152, in
_execute_mock_call
raise effect
RuntimeError: BROKEN
```
To make things worse, we would actually randomly use XmlClient or new one
depending on which SyncManager method we call.
This makes also inconvenient to replace the connection layer with a fake one
during tests to simulate stub responses. Furthermore the client of the manager
is also not propagated properly to the proxies created through that manager
making even less consistent the behaviour.
----------
components: Library (Lib)
messages: 366630
nosy: Alessandro Molina
priority: normal
severity: normal
status: open
title: multiprocessing.BaseManager does not retain Client type.
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue40307>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com