This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients asksol, jnoller, pen hill, pitrou
Date 2011-02-05.08:25:05
SpamBayes Score 5.4616867e-12
Marked as misclassified No
Message-id <1296894307.36.0.53669843253.issue11119@psf.upfronthosting.co.za>
In-reply-to
Content
Well, sockets cannot be pickled on any platform:

>>> sock = socket.create_connection(("www.python.org", 80))
__main__:1: ResourceWarning: unclosed <socket.socket object, fd=3, family=2, type=1, proto=0>
>>> s = pickle.loads(pickle.dumps(sock))
>>> s.getpeername()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
socket.error: getsockaddrlen: bad family
>>> s.fileno()
-1

The reason your code works under Linux is that multiprocessing uses fork() and therefore all objects and file handles are transparently inherited by the child. Windows doesn't have fork(), it instead spawns a new process to which it must marshal objects using pickle. You'll have to create your socket in the child for it to work at all.

By the way, multi-threading is much more appropriate than multi-processing when writing servers under Windows. Also, see the socketserver module for helpers to write both multi-threaded and multi-processed servers: http://docs.python.org/library/socketserver.html
History
Date User Action Args
2011-02-05 08:25:07pitrousetrecipients: + pitrou, jnoller, asksol, pen hill
2011-02-05 08:25:07pitrousetmessageid: <1296894307.36.0.53669843253.issue11119@psf.upfronthosting.co.za>
2011-02-05 08:25:06pitroulinkissue11119 messages
2011-02-05 08:25:05pitroucreate