-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update multiprocessing.managers.ListProxy and multiprocessing.managers.DictProxy #103134
Comments
ListProxy was written before list.clear and list.copy were added in 3.3. Since manager.list has all the other list methods, it seems straightforward to add the new methods. |
Dicts got |
``` from multiprocessing import Manager with Manager() as manager: xs = manager.list() xs.clear xs.copy d = manager.dict() d | {} # __or__ {} | d # __ror__ reversed(d) # __reversed__ d.fromkeys ``` suggested by @terryjreedy tested manually in Python 3.10.8 python#103134
Updated the pull request to add Waiting to hear back from @benjaminp to see whether it is safe to replace Also, is there a place to put unit tests? I guess to test this properly, we would need to launch two processes and check that changes in one process are reflected in changes in the other process... Not sure how we would write a unit test for that, although we can certainly test it manually. |
As an update, I did try removing
RESULTSACTUAL after replacing
EXPECTED and ACTUAL with current commits for this pull request (keep
|
Digging for one hour, I found it actually pretty simple. Try this one out, def f(x):
x += [1]
print(type(x))
x *= 2 When you find x has type class ListProxy(BaseListProxy):
def __iadd__(self, value):
self._callmethod('extend', (value,))
return self
def __imul__(self, value):
self._callmethod('__imul__', (value,))
return self This cpython/Lib/multiprocessing/managers.py Lines 808 to 811 in a0305c5
|
@sunmy2019 thanks so much for the important hint. I was able to make BaseDictProxy = MakeProxyType('DictProxy', (
'__contains__', '__delitem__', '__getitem__', '__ior__', '__iter__',
'__len__', '__or__', '__reversed__', '__ror__', '__setitem__', 'clear',
'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem',
'setdefault', 'update', 'values',
))
class DictProxy(BaseDictProxy):
_method_to_typeid_ = {
'__iter__': 'Iterator',
}
def __ior__(self, value):
self._callmethod('__ior__', (value,))
return self I finished adding the tests and the pull request is ready for review. |
thanks for taking this on! |
Feature or enhancement
Standard lists accept
clear
as a shortcut fordel xs[:]
However,
multiprocessing.ListProxy
omitted support forclear()
.raises the following exception
Pitch
If
clear
is supported in a standard list, it should be supported in a multiprocessing list!Previous discussion
This issue was not previously discussed.
Linked PRs
The text was updated successfully, but these errors were encountered: