Show More
@@ -3,6 +3,10 b' import readline' | |||||
3 | import time |
|
3 | import time | |
4 | import sys |
|
4 | import sys | |
5 | stdout = sys.stdout |
|
5 | stdout = sys.stdout | |
|
6 | ||||
|
7 | class TimeoutError(Exception): | |||
|
8 | pass | |||
|
9 | ||||
6 | class ClientCompleter2p(object): |
|
10 | class ClientCompleter2p(object): | |
7 | """Client-side completion machinery. |
|
11 | """Client-side completion machinery. | |
8 |
|
12 | |||
@@ -23,30 +27,25 b' class ClientCompleter2p(object):' | |||||
23 | dict(text=text, line=line)) |
|
27 | dict(text=text, line=line)) | |
24 | # send completion request to kernel |
|
28 | # send completion request to kernel | |
25 | # Give the kernel up to 0.5s to respond |
|
29 | # Give the kernel up to 0.5s to respond | |
26 | msg_matches = None |
|
|||
27 | for i in range(5): |
|
30 | for i in range(5): | |
28 | if self.km.xreq_channel.was_called(): |
|
31 | if self.km.xreq_channel.was_called(): | |
29 | msg_xreq = self.km.xreq_channel.get_msg() |
|
32 | msg_xreq = self.km.xreq_channel.get_msg() | |
30 |
if msg["header"]['session'] == msg_xreq["parent_header"]['session'] |
|
33 | if msg["header"]['session'] == msg_xreq["parent_header"]['session'] and \ | |
31 |
|
|
34 | msg_xreq["content"]["status"] == 'ok' and \ | |
32 |
|
|
35 | msg_xreq["msg_type"] == "complete_reply" : | |
33 |
|
|
36 | return msg_xreq["content"]["matches"] | |
34 |
|
|
37 | ||
35 | time.sleep(0.1) |
|
38 | time.sleep(0.1) | |
36 | return msg_matches |
|
39 | raise TimeoutError | |
37 |
|
40 | |||
38 | def complete(self, text, state): |
|
41 | def complete(self, text, state): | |
39 |
if state == 0 |
|
42 | if state == 0: | |
40 | self.matches = self.complete_request(text) |
|
43 | try: | |
41 |
|
44 | self.matches = self.complete_request(text) | ||
42 | if self.matches is None: |
|
45 | except TimeoutError: | |
43 | self.matches = [] |
|
46 | print('WARNING: Kernel timeout on tab completion.') | |
44 | print('WARNING: Kernel timeout on tab completion.') |
|
47 | ||
45 | #print self.matches |
|
|||
46 | try: |
|
48 | try: | |
47 | return self.matches[state] |
|
49 | return self.matches[state] | |
48 | except IndexError: |
|
50 | except IndexError: | |
49 | return None |
|
51 | return None | |
50 |
|
||||
51 |
|
||||
52 |
|
General Comments 0
You need to be logged in to leave comments.
Login now