Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why sock.bind is always report 10048 error when in a script with multiprocessing

Reply
Thread Tools

Why sock.bind is always report 10048 error when in a script with multiprocessing

 
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
Hi All, I'm trying to leverage my core i5 to send more UDP packets with multiprocssing, but I found a interesting thing is that the socket.bind is always reporting 10048 error even the process didn't do anything about the socket.
Here is the script

import threading,socket,random,pp,os
import time
from multiprocessing import Process
import multiprocessing.reduction

localIP='10.80.2.24'
localPort=2924
remoteIP='10.80.5.143'
remotePort=2924
sock=socket.socket(socket.AF_INET,socket.SOCK_DGRA M)
#sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind((localIP,localPort))
sock.connect((remoteIP,remotePort))

addRequest="MEGACO/1 ["+localIP+"]:"+str(localPort)+"\r\nTRANSACTION = 100 {\r\n" \
"\tCONTEXT = $ {\r\n" \
"\t\tADD = TDMs15c1f1/11{ \r\n" \
" Media { LocalControl { Mode=SendReceive,tdmc/ec=on }} " \
"\t}\r\n}}\r\n"

def sendAddRequest(sock,addRequst):
#for i in range(2500):
#sock.send(addRequest)
print "hello"



if __name__ == '__main__':
reader = Process(target=sendAddRequest,args=(sock,addReques t))
reader.start()


Here is the output

D:\Python test>mythread2.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 346, in main
prepare(preparation_data)
File "C:\Python27\lib\multiprocessing\forking.py", line 461, in prepare
'__parents_main__', file, path_name, etc
File "D:\Python test\mythread2.py", line 12, in <module>
sock.bind((localIP,localPort))
File "C:\Python27\lib\socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 10048] Only one usage of each socket address (protocol/netw
ork address/port) is normally permitted
 
Reply With Quote
 
 
 
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
I did a test on linux, it works well, so the issue is related to os.

 
Reply With Quote
 
 
 
 
Chris Angelico
Guest
Posts: n/a
 
      11-18-2011
On Fri, Nov 18, 2011 at 9:23 PM, Junfeng Hu <(E-Mail Removed)> wrote:
> Hi All, I'm trying to leverage my core i5 to send more UDP packets with multiprocssing, but I found a interesting thing is that the socket.bind is always reporting 10048 error even the process didn't do anything about the socket.
> sock.bind((localIP,localPort))
> socket.error: [Errno 10048] Only one usage of each socket address (protocol/netw
> ork address/port) is normally permitted


Try setting the socket to SO_REUSEADDR.

ChrisA
 
Reply With Quote
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
Thanks
Yes, I had tried this before, so you could find that I comment the line
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Here is the results.
D:\Python test>mythread2.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 347, in main
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1133, in load_reduce
value = func(*args)
File "C:\Python27\lib\multiprocessing\reduction.py" , line 167, in rebuild_sock
et
_sock = fromfd(fd, family, type_, proto)
File "C:\Python27\lib\multiprocessing\reduction.py" , line 156, in fromfd
s = socket.fromfd(fd, family, type_, proto)
AttributeError: 'module' object has no attribute 'fromfd'
 
Reply With Quote
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
Thanks
Yes, I had tried this before, so you could find that I comment the line
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Here is the results.
D:\Python test>mythread2.py
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 347, in main
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1378, in load
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 858, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 1133, in load_reduce
value = func(*args)
File "C:\Python27\lib\multiprocessing\reduction.py" , line 167, in rebuild_sock
et
_sock = fromfd(fd, family, type_, proto)
File "C:\Python27\lib\multiprocessing\reduction.py" , line 156, in fromfd
s = socket.fromfd(fd, family, type_, proto)
AttributeError: 'module' object has no attribute 'fromfd'
 
Reply With Quote
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
And actually ,the socket hadn't been used in this script.

 
Reply With Quote
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
And actually ,the socket hadn't been used in this script.

 
Reply With Quote
 
Chris Angelico
Guest
Posts: n/a
 
      11-18-2011
On Sat, Nov 19, 2011 at 2:51 AM, Junfeng Hu <(E-Mail Removed)> wrote:
> And actually ,the socket hadn't been used in this script.


Doesn't matter that you haven't used it; you're binding to the port,
that's what causes the 10048.

I think the main problem is that you're trying to share sockets across
processes, but I haven't used the Python multiprocessing module with
sockets before. I would recommend, if you can, creating separate
sockets in each subprocess; that might make things a bit easier.

ChrisA
 
Reply With Quote
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
Hi Chris.
The socket only binded once. That's the problem I'm puzzleing, I think it may a bug of multiprocessing in windows, or something I missed.
 
Reply With Quote
 
Junfeng Hu
Guest
Posts: n/a
 
      11-18-2011
Hi Chris.
The socket only binded once. That's the problem I'm puzzleing, I think it may a bug of multiprocessing in windows, or something I missed.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Parallel/Multiprocessing script design question Amit N Python 4 09-13-2007 08:07 PM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
getting rid of error report/ dont send error report Windows XP Computer Support 8 05-10-2004 06:34 PM
Q: simple sockets, bind, and socket error 10048 Johannes Eble Python 1 07-16-2003 12:20 PM



Advertisments