Issue1778
Created on 2011-07-23.06:57:00 by mitra, last changed 2011-07-30.00:06:19 by amak.
Messages | |||
---|---|---|---|
msg6579 (view) | Author: Anand Mitra (mitra) | Date: 2011-07-23.06:56:59 | |
I am creating a jython program which is started as a subprocess from python. The stdin and stdout are used to send pickled data which is used to call a java library. The jython process is constantly waiting in read and respond loop on the stdin and stdout. Since the pickle.load throws an exception if there is no data in the pipe, I decided to use select to wait until we have data on the stdin before calling the pickle. Unfortunately select is not working. I have reduced the reproduction case to a 3-liner which can be tried on the interactive prompt. Since this is holding up the project I am working on I would really appreciate if there is a known work-around which I can used till the time the bug is resolved. The same 3-liner works perfectly in python. $ java -classpath /opt/jython2.5.2/jython.jar org.python.util.jython Jython 2.5.2 (Release_2_5_2:7206, Mar 2 2011, 23:12:06) [OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_20 Type "help", "copyright", "credits" or "license" for more information. >>> import sys >>> import select >>> select.select([sys.stdin], [], []) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/jython2.5.2/Lib/select.py", line 225, in native_select pobj.register(fd, POLLIN) File "/opt/jython2.5.2/Lib/select.py", line 98, in register channel = _getselectable(socket_object) File "/opt/jython2.5.2/Lib/select.py", line 98, in register channel = _getselectable(socket_object) File "/opt/jython2.5.2/Lib/select.py", line 59, in _getselectable raise TypeError("Object '%s' is not watchable" % selectable_object, TypeError: ("Object '<open file '<stdin>', mode 'r' at 0x2>' is not watchable", 88) >>> |
|||
msg6580 (view) | Author: Anand Mitra (mitra) | Date: 2011-07-23.07:06:21 | |
did bit of searching and found the following article explaining this limitation. http://wiki.python.org/jython/SelectModule I am exploring a work around right now. Please do drop a note if you are aware of a simple work around for my requirement. |
|||
msg6590 (view) | Author: Alan Kennedy (amak) | Date: 2011-07-30.00:06:18 | |
Unfortunately, as you have discovered, stdin and stdout are not selectable objects on the Java Virtual Machine. http://wiki.python.org/jython/SelectModule#Only_sockets_can_be_multiplexed.2C_not_files_or_any_other_IO_channel This is a fundamental limitation of java, and thus cannot be solved in jython. Your only solution is to use channels that *are* selectable in java, and thus jython. In the current jython implementation, the only selectable IO channels are AF_INET and AF_INET6 sockets. To make your scenario work, you must 1. Make your parent process open a socket using the "listen" call. 2. Make your child process connect to the parent using the "connect" call. 3. Make the two communicate over that socket. To see some examples of such client to server communication, between threads, see the Lib/test_socket.py module. To see examples of such client to server communications, between processes, see this article http://docs.python.org/release/2.5.2/lib/socket-example.html Without knowing more about the nature of the communications between your parent and child, I cannot make any further recommendations. If you want alternative solutions, I suggest a question on the jython-users mailing list, providing more details of your use case. |
History | |||
---|---|---|---|
Date | User | Action | Args |
2011-07-30 00:06:19 | amak | set | status: open -> closed title: select system call does not work in jython -> Using the select system call on stdin does not work in jython nosy: + amak messages: + msg6590 assignee: amak resolution: rejected |
2011-07-23 07:06:21 | mitra | set | messages: + msg6580 |
2011-07-23 06:57:00 | mitra | create |
Supported by Python Software Foundation,
Powered by Roundup