Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #15880 > unrolled thread
| Started by | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| First post | 2011-11-18 02:23 -0800 |
| Last post | 2011-11-18 18:45 -0800 |
| Articles | 13 — 3 participants |
Back to article view | Back to comp.lang.python
Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 02:23 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 07:20 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Chris Angelico <rosuav@gmail.com> - 2011-11-19 02:33 +1100
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 07:48 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 07:48 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 07:51 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 07:51 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Chris Angelico <rosuav@gmail.com> - 2011-11-19 03:04 +1100
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 08:11 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 08:11 -0800
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Chris Angelico <rosuav@gmail.com> - 2011-11-19 03:16 +1100
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing MRAB <python@mrabarnett.plus.com> - 2011-11-18 16:55 +0000
Re: Why sock.bind is always report 10048 error when in a script with multiprocessing Junfeng Hu <hujunfeng@gmail.com> - 2011-11-18 18:45 -0800
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 02:23 -0800 |
| Subject | Why sock.bind is always report 10048 error when in a script with multiprocessing |
| Message-ID | <12715937.830.1321611809592.JavaMail.geo-discussion-forums@yqoo7> |
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
[toc] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 07:20 -0800 |
| Message-ID | <15167697.1495.1321629620458.JavaMail.geo-discussion-forums@yqoo7> |
| In reply to | #15880 |
I did a test on linux, it works well, so the issue is related to os.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-11-19 02:33 +1100 |
| Message-ID | <mailman.2829.1321630394.27778.python-list@python.org> |
| In reply to | #15880 |
On Fri, Nov 18, 2011 at 9:23 PM, Junfeng Hu <hujunfeng@gmail.com> 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
[toc] | [prev] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 07:48 -0800 |
| Message-ID | <mailman.2830.1321631319.27778.python-list@python.org> |
| In reply to | #15891 |
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'
[toc] | [prev] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 07:48 -0800 |
| Message-ID | <14330307.286.1321631316567.JavaMail.geo-discussion-forums@yqcm23> |
| In reply to | #15891 |
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'
[toc] | [prev] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 07:51 -0800 |
| Message-ID | <mailman.2831.1321631512.27778.python-list@python.org> |
| In reply to | #15893 |
And actually ,the socket hadn't been used in this script.
[toc] | [prev] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 07:51 -0800 |
| Message-ID | <674531.1586.1321631509432.JavaMail.geo-discussion-forums@yqhd1> |
| In reply to | #15893 |
And actually ,the socket hadn't been used in this script.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-11-19 03:04 +1100 |
| Message-ID | <mailman.2832.1321632261.27778.python-list@python.org> |
| In reply to | #15895 |
On Sat, Nov 19, 2011 at 2:51 AM, Junfeng Hu <hujunfeng@gmail.com> 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
[toc] | [prev] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 08:11 -0800 |
| Message-ID | <mailman.2833.1321632703.27778.python-list@python.org> |
| In reply to | #15898 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 08:11 -0800 |
| Message-ID | <15809319.188.1321632700957.JavaMail.geo-discussion-forums@yqdr22> |
| In reply to | #15898 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2011-11-19 03:16 +1100 |
| Message-ID | <mailman.2834.1321633010.27778.python-list@python.org> |
| In reply to | #15900 |
On Sat, Nov 19, 2011 at 3:11 AM, Junfeng Hu <hujunfeng@gmail.com> wrote: > 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. I don't know how multiprocessing goes about initializing those subprocesses; I suspect that's where it creates the additional sockets. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | MRAB <python@mrabarnett.plus.com> |
|---|---|
| Date | 2011-11-18 16:55 +0000 |
| Message-ID | <mailman.2835.1321635315.27778.python-list@python.org> |
| In reply to | #15893 |
On 18/11/2011 15:48, Junfeng Hu wrote:
> 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'
The documentation for socket.fromfd says:
Availability: Unix.
You're using Microsoft Windows.
[toc] | [prev] | [next] | [standalone]
| From | Junfeng Hu <hujunfeng@gmail.com> |
|---|---|
| Date | 2011-11-18 18:45 -0800 |
| Message-ID | <5e4635df-936f-4f5d-b3c9-ad4370a3be64@j10g2000vbe.googlegroups.com> |
| In reply to | #15903 |
On Nov 18, 10:55 am, MRAB <pyt...@mrabarnett.plus.com> wrote: > On 18/11/2011 15:48, Junfeng Hu wrote: > > > > > > > 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' > > The documentation for socket.fromfd says: > > Availability: Unix. > > You're using Microsoft Windows.- Hide quoted text - > > - Show quoted text - Yes, but my question is , how to make such script work in windows.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web