You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sending Connection-objects over multiprocessing connections fails #49142
It seems the old pyprocessing (http://pyprocessing.berlios.de/) can do
some things that the new multiprocessing package can not;
sending/receiving connection objects for one.
This is a quite handy functionality, so it would be nice if it were
reintroduced.
Also, the error message isn't very helpful.
Failing test below.
$ python2.6 pipetest2.py
asdf
Traceback (most recent call last):
File "a.py", line 10, in <module>print c1.recv()
TypeError: Required argument 'handle' (pos 1) not found
thanks for filing this. I'll need to compare the two code bases and figure
out why it's either regressed, or Richard removed it prior to the
integration.
Before I can logically support this, I need a clear use case that supports
the idea that this should be supported in the current version of
multiprocessing.
dsvensson commented on Aug 26, 2009
dsvenssonmannequin
Mannequin
More actions
A typical use case would be for a server to receive a connection, and
then send that connection over to another process that does the actual
work. This used to work with pyprocessing, and the support seems to be
available in multiprocessing.c -> multiprocessing_sendfd, but not used.
dsvensson commented on Aug 26, 2009
dsvenssonmannequin
Mannequin
More actions
And to be clear, I have enabled connection pickling by issuing:
Ehm.. completly broken url in prev message.. Revision 65016, "Apply
Amaury's patch to multiprocessing for bpo-3125, removes the copy_reg
and replaces it with ForkingPickler.register(), which should resolve the
conflict with the global registry/ctypes" is what I'm refering to.
Without this patch, the reducers/rebuilders are properly registered in
the pickler that connection.h (srsly, code in header files?) later uses.
11 remaining items
Jimbofbx commented on Apr 7, 2012
Jimbofbxmannequin
Mannequin
More actions
Shouldn't reduce_pipe_connection just be an alias for reduce_connection in unix so that using reduce_pipe_connection would work for both win and unix? My understanding after looking at the code is that reduce_pipe_connection isn't defined for non-win32, although I haven't tested it to see if that's true.
Of course, ideally a pipe connection would just pickle and unpickle properly out-of-the-box, which I think was the original intent.
Here's a complete, working example with Python 3.2 tested on Win 7 64-bit:
There is an undocumented function multiprocessing.allow_connection_pickling() whose docstring claims it allows connection and socket objects to be pickled.
The attached patch fixes the multiprocessing.reduction module so that it works correctly. This means that TestPicklingConnections can be reenabled in the unit tests.
The patch uses the new socket.share() and socket.fromshare() methods on Windows.
Unless there's a technical barrier, I still think it would be better to use ForkingPickler in multiprocessing.connection, rather than modify global state (copyreg). The pickling support is multiprocessing-specific and wouldn't make sense for other pickles (e.g. stored to disk).
kristjanvalur commented on Apr 9, 2012
kristjanvalurmannequin
Mannequin
More actions
I just want to point out that each time socket.share() is called, the resulting data can only be used once by socket.fromshare(). I'm mentioning this because I know there is some caching mechanism in reduction.py and that this data is not cacheable/reuseable.
sbt commented on Apr 10, 2012
sbtmannequin
Mannequin
More actions
Updated patch which uses ForkingPickler in Connection.send().
Note that connection sharing still has to be enabled using allow_connection_pickling().
Support could be enabled automatically, but that would introduce more circular imports which confuse me. It might be worthwhile refactoring to eliminate all circular imports.
Support could be enabled automatically, but that would introduce more
circular imports which confuse me.
Are you sure? AFAICT:
connection depends on forking
reduction depends on forking and connection
But connection doesn't depend on reduction, neither does forking.
sbt commented on Apr 10, 2012
sbtmannequin
Mannequin
More actions
But connection doesn't depend on reduction, neither does forking.
If registration of (Pipe)Connection is done in reduction then you can't make (Pipe)Connection picklable *automatically* unless you make connection depend on reduction (possibly indirectly).
A circular import can be avoided by making reduction not import connection at module level. So not hard to fix.
sbt commented on Apr 11, 2012
sbtmannequin
Mannequin
More actions
The last patch did not work on Unix.
Here is a new version where the reduction functions are automatically registered, so allow_connection_pickling() is redundant.
Could you regenerate your patch now that the win32 -> _winapi changes have been applied?
sbt commented on Apr 19, 2012
sbtmannequin
Mannequin
More actions
Up to date patch.
sbt commented on Apr 19, 2012
sbtmannequin
Mannequin
More actions
A couple of minor changes based on Antoine's earlier review (which I did not notice till now).
python-dev commented on Apr 24, 2012
python-devmannequin
Mannequin
More actions
New changeset 08d4c2fe51ea by Antoine Pitrou in branch 'default':
Issue bpo-4892: multiprocessing Connections can now be transferred over multiprocessing Connections. http://hg.python.org/cpython/rev/08d4c2fe51ea
Activity
gsson commentedon Jan 9, 2009
It seems the old pyprocessing (http://pyprocessing.berlios.de/) can do
some things that the new multiprocessing package can not;
sending/receiving connection objects for one.
This is a quite handy functionality, so it would be nice if it were
reintroduced.
Also, the error message isn't very helpful.
Failing test below.
$ uname -a Darwin midori.local 9.6.0 Darwin Kernel Version 9.6.0: Mon Nov 24 17:37:00 PST 2008; root:xnu-1228.9.59~1/RELEASE_I386 i386gsson commentedon Jan 9, 2009
c1, c2 = Pipe(duplex=False)
c2.send('asdf')
print c1.recv()
c2.send(c1)
print c1.recv()
jnoller commentedon Jan 9, 2009
thanks for filing this. I'll need to compare the two code bases and figure
out why it's either regressed, or Richard removed it prior to the
integration.
jnoller commentedon Mar 30, 2009
Before I can logically support this, I need a clear use case that supports
the idea that this should be supported in the current version of
multiprocessing.
dsvensson commentedon Aug 26, 2009
A typical use case would be for a server to receive a connection, and
then send that connection over to another process that does the actual
work. This used to work with pyprocessing, and the support seems to be
available in multiprocessing.c -> multiprocessing_sendfd, but not used.
dsvensson commentedon Aug 26, 2009
And to be clear, I have enabled connection pickling by issuing:
dsvensson commentedon Aug 26, 2009
When reverting this commit stuff works:
http://svn.python.org/view/python/trunk/Lib/multiprocessing/reduction.py?r1=64257&r2=65016
dsvensson commentedon Aug 26, 2009
Ehm.. completly broken url in prev message.. Revision 65016, "Apply
Amaury's patch to multiprocessing for bpo-3125, removes the copy_reg
and replaces it with ForkingPickler.register(), which should resolve the
conflict with the global registry/ctypes" is what I'm refering to.
Without this patch, the reducers/rebuilders are properly registered in
the pickler that connection.h (srsly, code in header files?) later uses.
11 remaining items
Jimbofbx commentedon Apr 7, 2012
Shouldn't reduce_pipe_connection just be an alias for reduce_connection in unix so that using reduce_pipe_connection would work for both win and unix? My understanding after looking at the code is that reduce_pipe_connection isn't defined for non-win32, although I haven't tested it to see if that's true.
Of course, ideally a pipe connection would just pickle and unpickle properly out-of-the-box, which I think was the original intent.
Here's a complete, working example with Python 3.2 tested on Win 7 64-bit:
sbt commentedon Apr 9, 2012
There is an undocumented function multiprocessing.allow_connection_pickling() whose docstring claims it allows connection and socket objects to be pickled.
The attached patch fixes the multiprocessing.reduction module so that it works correctly. This means that TestPicklingConnections can be reenabled in the unit tests.
The patch uses the new socket.share() and socket.fromshare() methods on Windows.
pitrou commentedon Apr 9, 2012
Unless there's a technical barrier, I still think it would be better to use ForkingPickler in multiprocessing.connection, rather than modify global state (copyreg). The pickling support is multiprocessing-specific and wouldn't make sense for other pickles (e.g. stored to disk).
kristjanvalur commentedon Apr 9, 2012
I just want to point out that each time socket.share() is called, the resulting data can only be used once by socket.fromshare(). I'm mentioning this because I know there is some caching mechanism in reduction.py and that this data is not cacheable/reuseable.
sbt commentedon Apr 10, 2012
Updated patch which uses ForkingPickler in Connection.send().
Note that connection sharing still has to be enabled using allow_connection_pickling().
Support could be enabled automatically, but that would introduce more circular imports which confuse me. It might be worthwhile refactoring to eliminate all circular imports.
pitrou commentedon Apr 10, 2012
Are you sure? AFAICT:
But connection doesn't depend on reduction, neither does forking.
sbt commentedon Apr 10, 2012
If registration of (Pipe)Connection is done in reduction then you can't make (Pipe)Connection picklable *automatically* unless you make connection depend on reduction (possibly indirectly).
A circular import can be avoided by making reduction not import connection at module level. So not hard to fix.
sbt commentedon Apr 11, 2012
The last patch did not work on Unix.
Here is a new version where the reduction functions are automatically registered, so allow_connection_pickling() is redundant.
pitrou commentedon Apr 18, 2012
Could you regenerate your patch now that the win32 -> _winapi changes have been applied?
sbt commentedon Apr 19, 2012
Up to date patch.
sbt commentedon Apr 19, 2012
A couple of minor changes based on Antoine's earlier review (which I did not notice till now).
python-dev commentedon Apr 24, 2012
New changeset 08d4c2fe51ea by Antoine Pitrou in branch 'default':
Issue bpo-4892: multiprocessing Connections can now be transferred over multiprocessing Connections.
http://hg.python.org/cpython/rev/08d4c2fe51ea
pitrou commentedon Apr 24, 2012
Thanks, Richard. I have now committed the patch. Hopefully the Windows buildbots will be ok :)