Show More
@@ -81,7 +81,8 b' class Frontend(object):' | |||
|
81 | 81 | print("history file can not be readed.") |
|
82 | 82 | |
|
83 | 83 | self.messages = {} |
|
84 | self.prompt_count = 0 | |
|
84 | ||
|
85 | self.prompt_count = self.km.xreq_channel.execute('', silent=True) | |
|
85 | 86 | self.backgrounded = 0 |
|
86 | 87 | self._splitter = InputSplitter() |
|
87 | 88 | |
@@ -95,11 +96,12 b' class Frontend(object):' | |||
|
95 | 96 | while self._splitter.push_accepts_more(): |
|
96 | 97 | code = raw_input('.....:'+' '*self._splitter.indent_spaces) |
|
97 | 98 | self._splitter.push(' '*self._splitter.indent_spaces+code) |
|
99 | except KeyboardInterrupt: | |
|
100 | print('\nKeyboardInterrupt\n') | |
|
101 | pass | |
|
102 | else: | |
|
98 | 103 | self._execute(self._splitter.source,False) |
|
99 | 104 | self._splitter.reset() |
|
100 | except KeyboardInterrupt: | |
|
101 | print('\nKeyboardInterrupt\n') | |
|
102 | pass | |
|
103 | 105 | |
|
104 | 106 | def start(self): |
|
105 | 107 | """ init a bucle that call interact method to get code. |
@@ -107,7 +109,10 b' class Frontend(object):' | |||
|
107 | 109 | """ |
|
108 | 110 | while True: |
|
109 | 111 | try: |
|
110 |
self.interact() |
|
|
112 | self.interact() | |
|
113 | except KeyboardInterrupt: | |
|
114 | print('\nKeyboardInterrupt\n') | |
|
115 | pass | |
|
111 | 116 | except EOFError: |
|
112 | 117 | answer = '' |
|
113 | 118 | while True: |
@@ -122,30 +127,68 b' class Frontend(object):' | |||
|
122 | 127 | |
|
123 | 128 | See parent class :meth:`execute` docstring for full details. |
|
124 | 129 | """ |
|
125 |
msg_id = self.km.xreq_channel.execute(source, hidden) |
|
|
126 |
|
|
|
127 | msg_xreq = self.km.xreq_channel.get_msg() | |
|
128 | print "xreq not implemented yet" | |
|
129 | ||
|
130 | if self.km.rep_channel.was_called(): | |
|
131 | msg_rep = self.km.rep_channel.get_msg() | |
|
132 | print "rep hadler not implemented yet" | |
|
130 | msg_id = self.km.xreq_channel.execute(source, hidden) | |
|
131 | self.handle_xrep_channel() | |
|
132 | ||
|
133 | # while self.km.rep_channel.was_called() : | |
|
134 | # msg_rep = self.km.rep_channel.get_msg() | |
|
135 | # print "rep hadler not implemented yet" | |
|
133 | 136 | |
|
134 | while True: | |
|
135 | if not self.km.sub_channel.was_called(): | |
|
136 | break | |
|
137 | print "calles sub0" | |
|
138 | sub_msg = self.km.sub_channel.get_msg() | |
|
139 | if self.km.session.username == sub_msg['parent_header']['username'] and self.km.session.session == sub_msg['parent_header']['session']: | |
|
140 | print "calles sub1" | |
|
141 | ||
|
142 | 137 | |
|
143 | def handle_sub_msg(self,msg): | |
|
144 | if msg['content'] == '': | |
|
145 | pass | |
|
138 | ||
|
139 | # self.km.xreq_channel.execute('', silent=True) | |
|
140 | def handle_xrep_channel(self): | |
|
141 | msg_header = self.km.session.msg_header() | |
|
142 | if self.km.xreq_channel.was_called(): | |
|
143 | msg_xreq = self.km.xreq_channel.get_msg() | |
|
144 | if msg_header["session"] == msg_xreq["parent_header"]["session"] : | |
|
145 | if msg_xreq["content"]["status"] == 'ok' : | |
|
146 | self.handle_sub_channel() | |
|
147 | ||
|
148 | else: | |
|
149 | print >> sys.stderr, "Error executing: ", source | |
|
150 | print >> sys.stderr, "Status in the kernel: ", msg_xreq["content"]["status"] | |
|
151 | self.prompt_count = msg_xreq["content"]["execution_count"] | |
|
152 | print msg_xreq | |
|
153 | else: | |
|
154 | print >> sys.stderr, "Kernel is busy!" | |
|
155 | ||
|
156 | ||
|
157 | def handle_sub_channel(self): | |
|
158 | """ Method to procces subscribe channel's messages | |
|
159 | ||
|
160 | this method read a message and procces the content | |
|
161 | in differents outputs like stdout, stderr, pyout | |
|
162 | and status | |
|
163 | ||
|
164 | Arguments: | |
|
165 | sub_msg: message receive from kernel in the sub socket channel | |
|
166 | capture by kernel manager. | |
|
167 | ||
|
168 | """ | |
|
169 | while self.km.sub_channel.was_called(): | |
|
170 | sub_msg = self.km.sub_channel.get_msg() | |
|
171 | if msg_header["username"] == sub_msg['parent_header']['username'] and self.km.session.session == sub_msg['parent_header']['session']: | |
|
172 | if sub_msg['msg_type'] == 'status' : | |
|
173 | if sub_msg["content"]["execution_state"] == "busy" : | |
|
174 | pass | |
|
175 | ||
|
176 | if sub_msg['msg_type'] == 'stream' : | |
|
177 | if sub_msg["content"]["name"] == "stdout": | |
|
178 | print >> sys.stdout,sub_msg["content"]["data"] | |
|
179 | sys.stdout.flush() | |
|
180 | if sub_msg["content"]["name"] == "stderr" : | |
|
181 | print >> sys.stderr,sub_msg["content"]["data"] | |
|
182 | sys.stderr.flush() | |
|
183 | ||
|
184 | if sub_msg['msg_type'] == 'pyout' : | |
|
185 | print >> sys.stdout,"Out[%i]:"%sub_msg["content"]["execution_count"], sub_msg["content"]["data"] | |
|
186 | sys.stdout.flush() | |
|
187 | ||
|
146 | 188 | |
|
147 | 189 | def start_frontend(): |
|
148 | 190 | """ Entry point for application. |
|
191 | ||
|
149 | 192 | """ |
|
150 | 193 | # Parse command line arguments. |
|
151 | 194 | parser = ArgumentParser() |
General Comments 0
You need to be logged in to leave comments.
Login now