Issue1021
Created on 2008年04月08日.15:43:31 by asterio, last changed 2008年04月08日.23:07:24 by amak.
| Messages | |||
|---|---|---|---|
| msg3138 (view) | Author: Alan Kennedy (amak) | Date: 2008年04月08日.16:16:41 | |
Need more details, e.g. what behaviour did you expect, and what behaviour did you actually get. And ideally, a code snippet which illustrates the problem. |
|||
| msg3139 (view) | Author: asterio (asterio) | Date: 2008年04月08日.16:49:59 | |
Sorry, was an accident while I was writing the Note.
Consider the following code:
fd=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
rnetLoc = ('127.0.0.1', 9000)
fd.setblocking(0)
fd.bind( rnetLoc ) # python fails here if address is in
use
fd.listen(5) # but jython fails here
If some code expects to detect an already binded address in bind()
function then will fails as bind() does send any exception, but
listen() does.
From my side I guess is a minor detail, just to be as near as possible
to the python behaviour.
Regards,
--
Asterio
|
|||
| msg3140 (view) | Author: Alan Kennedy (amak) | Date: 2008年04月08日.19:38:36 | |
This problem cannot be fixed.
It happens because jython must present a unified (cpython) interface to
both client and server sockets, which are actually implemented with
different objects on java, namely ServerSocket/Channel and Socket/Channel.
The only way that jython can know what type of underlying socket to
create is to wait for the user to call a method which indicates whether
the socket is a client or a server socket. In this case, that call is
the "listen()" call. The "bind()" is not enough, since both client and
server sockets can bind to an address.
This deferred creation of sockets is why the exception appears only
during the "listen()" call on jython.
This is not an important issue. In practice, running code will most
likely wrap the socket creation, binding and listening in a single
try..except anyway, which will catch the error identically on both
cpython and jython. Consider the following vesion of your code.
#---------------------------------------------------------------------
import errno, socket
try:
fd=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
rnetLoc = ('127.0.0.1', 9000)
fd.setblocking(0)
fd.bind( rnetLoc )
fd.listen(5)
except socket.error, se:
print "Exception binding to socket: %s" % se
if se[0] == errno.EADDRINUSE:
print "The address is already in use"
raise SystemExit
while True: pass
#---------------------------------------------------------------------
So the resolution on this bug is that it is not a bug, or if it is a
bug, then it is not possible to fix it.
However, I will leave the bug open for now, to give the reporter a
chance to complain about a "wontfix" resolution.
Thanks all the same for reporting it; your input is valued.
|
|||
| msg3141 (view) | Author: asterio (asterio) | Date: 2008年04月08日.22:01:41 | |
Thank you Alan, the explanation was very clear and useful. I agree with you. This is not a bug and can be easily treated. As far I can I will try to provide valuable feedback for jython. Regards, |
|||
| msg3142 (view) | Author: Alan Kennedy (amak) | Date: 2008年04月08日.23:07:24 | |
Closed by consensus. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2008年04月08日 23:07:24 | amak | set | status: open -> closed resolution: wont fix messages: + msg3142 |
| 2008年04月08日 22:01:41 | asterio | set | messages: + msg3141 |
| 2008年04月08日 19:38:37 | amak | set | messages: + msg3140 |
| 2008年04月08日 16:49:59 | asterio | set | messages: + msg3139 |
| 2008年04月08日 16:16:41 | amak | set | assignee: amak messages: + msg3138 nosy: + amak |
| 2008年04月08日 15:43:31 | asterio | create | |
Supported by Python Software Foundation,
Powered by Roundup