Why sock.bind is always report 10048 error when in a script with multiprocessing
Junfeng Hu
hujunfeng at gmail.com
Fri Nov 18 05:23:29 EST 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_DGRAM)
#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,addRequest))
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
More information about the Python-list
mailing list