Antoine Pitrou <[email protected]> added the comment:
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
----------
nosy: +pitrou
resolution: -> invalid
status: open -> pending
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue11119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com