Skip to content

Commit

Permalink
Repair the array copy speedup trick. Fixes tomerfiliba-org#236.
Browse files Browse the repository at this point in the history
The remote object needs to be an array already for __array__() to be accepted by Numpy.
  • Loading branch information
pilcru committed Feb 19, 2018
1 parent 64d638b commit 6d11add
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion rpyc/core/netref.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ def __getattribute__(self, name):
return self.__dir__()
elif name in _deleted_netref_attrs:
raise AttributeError()
elif name == "__array__": # Speedup array copy if the remote is an array
if hasattr(self, '__array__'):
return object.__getattribute__(self, "__array__")
else:
raise AttributeError()
else:
return object.__getattribute__(self, name)
elif name == "__call__": # IronPython issue #10
Expand Down Expand Up @@ -188,7 +193,8 @@ def __reduce_ex__(self, proto):

# This is not strictly necessary, but a performance optimization:
# Note that protocol=-1 will only work between python interpreters of the
# same version:
# same version.
# This method should only be called if the remote object implements __array__.
def __array__(self):
return pickle.loads(syncreq(self, consts.HANDLE_PICKLE, -1))

Expand Down

0 comments on commit 6d11add

Please sign in to comment.