Skip to content

Commit

Permalink
Merge pull request #309 from zpz/zepu
Browse files Browse the repository at this point in the history
Zepu
  • Loading branch information
zpz authored Jun 2, 2024
2 parents ad6b39b + c300982 commit fc84f24
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).


## [0.15.6] - in progress
## [0.15.6] - 2024-06-02

- Finetune `mpservice.multiprocessing.server_process`:
- support pickling of `ServerProcess` objects.
Expand Down
2 changes: 1 addition & 1 deletion src/mpservice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
python3 -m pip install mpservice
"""

__version__ = '0.15.5'
__version__ = '0.15.6'


from . import (
Expand Down
24 changes: 14 additions & 10 deletions src/mpservice/multiprocessing/server_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ def agent(data):
Value,
convert_to_error,
dispatch,
get_spawning_popen,
listener_client,
)
from multiprocessing.managers import (
Expand Down Expand Up @@ -482,9 +483,13 @@ def start(self, *args, **kwargs):
return z

def __reduce__(self):
if get_spawning_popen() is not None:
auth = self._authkey
else:
auth = None
return (
self._rebuild_manager,
(self.__class__, self._address, self._authkey, self._serializer),
(type(self), self._address, auth, self._serializer),
)

@staticmethod
Expand Down Expand Up @@ -685,7 +690,7 @@ def _decref(token, authkey, tls, idset, _Client, server):
# Changes to the standard version:
# 1. call `incref` before returning
# 2. use our custom `RebuildProxy` and `AutoProxy` in place of the standard versions
# 3. always include authkey
# 3. changes about returning authkey
def __reduce__(self):
# Inc refcount in case the remote object is gone before unpickling happens.
server = self._server
Expand All @@ -695,14 +700,13 @@ def __reduce__(self):
conn = self._Client(self._token.address, authkey=self._authkey)
dispatch(conn, None, 'incref', (self._id,))

# kwds = {}
# if get_spawning_popen() is not None:
# kwds['authkey'] = self._authkey
kwds = {'authkey': bytes(self._authkey)}
# TODO: this bypasses a security check, hence must be not quite right.
# This authkey is needed if user has specified a custom authkey to `BaseManager.__init__`.
# If this authkey is not included, the rebuilt proxy object would not be able to communicate
# with the server.
kwds = {}
if get_spawning_popen() is not None:
kwds['authkey'] = self._authkey
elif self._server:
kwds = {'authkey': bytes(self._authkey)}
# Bypass a security check of `multiprocessing.process.AuthenticationString`,
# because returning a proxy from the server is safe.

if getattr(self, '_isauto', False):
kwds['exposed'] = self._exposed_
Expand Down

0 comments on commit fc84f24

Please sign in to comment.