Issue1745068
Created on 2007-06-28.21:13:35 by rluse, last changed 2007-07-01.19:19:27 by amak.
Messages | |||
---|---|---|---|
msg1683 (view) | Author: Bob Luse (rluse) | Date: 2007-06-28.21:13:35 | |
Hi, I am having an issue with select. I am thinking that it may be Java version related. When I run this script: import socket, select import sys print sys.version print sys.platform s1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s1.bind(('', 9000)) s1.listen(1) s2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s2.bind(('', 9001)) s2.listen(5) while True: input, output, exc = select.select([s1, s2], [], [], 0) for sock in input: client = sock.accept() print 'accepting client' time.sleep(1.0) client.close() print 'client closed' I get this for a result: 2.2rc1 java1.6.0_01 Traceback (innermost last): File "C:\Documents and Settings\bob\My Documents\WirelessX\Jython22Tests\src\SimpleSelectServer.py", line 18, in ? File "C:\jython2.2rc1\Lib\select.py", line 137, in select File "C:\jython2.2rc1\Lib\select.py", line 74, in register File "C:\jython2.2rc1\Lib\select.py", line 54, in _register_channel at java.nio.channels.spi.AbstractSelectableChannel.register(Unknown Source) at java.nio.channels.SelectableChannel.register(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) java.nio.channels.IllegalBlockingModeException: java.nio.channels.IllegalBlockingModeException I am putting the version and platform info in this, because I think I am using a newer version of Java than you are. |
|||
msg1684 (view) | Author: Alan Kennedy (amak) | Date: 2007-06-29.11:55:28 | |
The select behaviour is correct. However, the error message should be a lot clearer. You have to put your sockets into non-blocking mode in order for your code to work. So before you do the select call, do this s1.setblocking(0) s2.setblocking(0) You can see this in the java documentation by looking at the docs for IllegalBlockingModeException http://java.sun.com/j2se/1.4.2/docs/api/java/nio/channels/IllegalBlockingModeException.html Which says " ... exception thrown when a blocking-mode-specific operation is invoked upon a channel in the incorrect blocking mode.". I need to clean up the exception handling in this case to better explain what is happening. |
|||
msg1685 (view) | Author: Bob Luse (rluse) | Date: 2007-06-29.14:54:02 | |
Yeah, I was afraid it would be something like that. The message is confusing though. A message something like 'Cannot perform select on a blocking socket...' would have been a little less confusing. |
|||
msg1686 (view) | Author: Alan Kennedy (amak) | Date: 2007-06-29.15:58:46 | |
OK, glad that sorted it out. Although this is now, strictly speaking an invalid bug report, I am going to leave it open as a reminder that I need to change that exception message to be more explanatory. |
|||
msg1687 (view) | Author: Bob Luse (rluse) | Date: 2007-06-29.17:08:11 | |
Thats fine with me. |
|||
msg1688 (view) | Author: Alan Kennedy (amak) | Date: 2007-07-01.19:19:27 | |
OK, closing this bug now. I have checked in code which maps the IllegalBlockingModeException to a select.error exception, with the error code corresponding to a newly introduced symbolic constant Jython 2.2rc1 on java1.4.2_13 Type "copyright", "credits" or "license" for more information. >>> import socket, select, errno >>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) >>> s.connect(('localhost',80)) >>> select.select([s],[],[]) Traceback (innermost last): File "<console>", line 1, in ? File "C:\jython_trunk\jython\dist\Lib\select.py", line 179, in select File "C:\jython_trunk\jython\dist\Lib\select.py", line 102, in register error: (20000, 'socket must be in non-blocking mode') >>> errno.errorcode[20000] 'ESOCKISBLOCKING' >>> |
History | |||
---|---|---|---|
Date | User | Action | Args |
2007-06-28 21:13:35 | rluse | create |
Supported by Python Software Foundation,
Powered by Roundup