[IPython-dev] IPythonQt/ZMQ raw_input support issue.
Gerardo Gutierrez
muzgash.lists at gmail.com
Fri Jul 2 09:19:25 EDT 2010
Hi everyone.
I've been trying to implement from the examples in
pyzmq<http://github.com/ellisonbg/pyzmq>the support for raw_input
calls, to be used in IPthonZMQ and IPythonQt
projects.
Nothing goo has come from this attempts but a better understanding of what I
don't understand. Here's a guide through my last thoughts so you can help
me:
firs I wanted to add to this line(154) in the kernel, a new type of request:
*
*
*for msg_type in ['execute_request', 'complete_request','**raw_input_request
**']:**
** self.handlers[msg_type] = getattr(self, msg_type)*
Also I need to add a function:
*
*
*def raw_input_request(self,ident,parent):*
* print>>sys.__stdout__,"entered"*
*
*
Just to check if the messages thread gets there (Which it doesn't).*
*
The class RawInput is as it was always.
And obviously the overwriting of the raw_input function in main():
*rawinput=RawInput(session,pub_socket)
__builtin__.raw_input=rawinput*
*
*
Now for the frontend part, I need also a msg_type:*
*
*for msg_type in ['pyin', 'pyout', 'pyerr', 'stream','raw_input']:
self.handlers[msg_type] = getattr(self, 'handle_%s' % msg_type)*
And a handler for raw_input type of messages:
*def handle_raw_input(self,omsg):
stdin_msg=sys.stdin.readline()
src=stdin_msg
self.session.send(self.request_socket,'raw_input_request',dict(code=src))*
As you can see this is just to send the raw_input request with the line
written by the user.
The error is this:
*<class 'zmq._zmq.ZMQError'> : Operation not supported
Traceback (most recent call last):
File "./kernel.py", line 194, in execute_request
exec comp_code in self.user_ns, self.user_ns
File "<zmq-kernel>", line 1, in <module>
File "./kernel.py", line 126, in __call__
reply=self.socket.recv_json()
File "_zmq.pyx", line 906, in zmq._zmq.Socket.recv_json (zmq/_zmq.c:6862)
File "_zmq.pyx", line 751, in zmq._zmq.Socket.recv (zmq/_zmq.c:5316)
File "_zmq.pyx", line 781, in zmq._zmq.Socket._recv_copy (zmq/_zmq.c:5690)
ZMQError: Operation not supported*
*
*
It says that the error is in *exec comp_code in self.user_ns, self.user_ns*,
which is in the execute_request function
{u'content': {u'code': u'raw_input()'},
u'header': {u'username': u'muzgash', u'msg_id': 0, u'session':
u'264d21d4-7e00-4b7e-b051-3c0ba7b221f6'},
u'msg_type': u'execute_request',
u'parent_header': {}}
{'content': {u'status': u'error', u'etype': u"<class 'zmq._zmq.ZMQError'>",
u'evalue': u'Operation n..........
so I can say that the error is in the first message sent by the frontend to
the kernel, but the raw_input function is called ( RawInput.__call__() ) and
also a message is sent to the frontend through:
msg = self.session.msg(u'raw_input')
self.socket.send_json(msg)
and the function handle_raw_input is called, which sends a new message to
the kernel
{u'content': {u'code': u'input-->\n'},
u'header': {u'username': u'muzgash', u'msg_id': 1, u'session':
u'264d21d4-7e00-4b7e-b051-3c0ba7b221f6'},
u'msg_type': u'raw_input_request',
u'parent_header': {}}
so this line in the class RawInput should recieve it:
while True:
try:
reply = self.socket.recv_json(zmq.NOBLOCK)
But it doesn't.
That's one thing.
Another one is that for this to work well in the Qt frontend I need to fix
pyout (keeping off course multiline input) which I have no clue how to do
it.
I could write a pretty crude fix with Qt and without requesting the kernel
twice, but no _NN call will work and it will have to be rewritten when this
problems are solved.
So I think for now I'll move on to the next point in the schedule 'till some
ideas popup.
thanks in advance.
Best regards.
--
Gerardo Gutiérrez Gutiérrez <http://he1.udea.edu.co/gweb>
Physics student
Universidad de Antioquia
Computational physics and astrophysics group
(FACom<http://urania.udea.edu.co/sites/sites.php>
)
Computational science and development
branch(FACom-dev<http://urania.udea.edu.co/sites/facom-dev/>
)
Usuario Linux #492295
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20100702/b7d0a6d7/attachment.html>
More information about the IPython-dev
mailing list