~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to scripts/python-console

  • Committer: wagrant
  • Date: 2008-07-10 06:57:50 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:846
python-console: Print proper tracebacks on exceptions. They actually
                match CPython and are useful now! Although we'll
                hopefully turn them off by default later.

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
import signal
12
12
import socket
13
13
import sys
 
14
import traceback
14
15
from threading import Thread
15
16
from functools import partial
16
17
 
133
134
            self.webio.flush()
134
135
            self.cmdQ.put({"okay":res})
135
136
            self.curr_cmd = ''
136
 
        except Exception, exc:
 
137
        except:
 
138
            tb = format_exc_start(start=1)
137
139
            self.webio.flush()
138
 
            exc_classname = exc.__class__.__name__
139
 
            self.cmdQ.put({"exc": exc_classname + ": " + str(exc)})
 
140
            self.cmdQ.put({"exc": ''.join(tb)})
140
141
            self.curr_cmd = ''
141
142
 
142
143
    def run(self):
161
162
                        self.cmdQ.put({"more":None})
162
163
                    else:
163
164
                        self.execCmd(cmd)
164
 
                except Exception, exc:
 
165
                except:
 
166
                    tb = format_exc_start(start=3)
 
167
                    self.cmdQ.put({"exc": ''.join(tb)})
165
168
                    self.webio.flush()
166
 
                    self.cmdQ.put({"exc":str(exc)})
167
169
                    self.curr_cmd = ''
168
170
            if 'block' in ln:
169
171
                # throw away a partial command.
170
172
                try:
171
173
                    cmd = compile(ln['block'], "<web session>", 'exec');
172
174
                    self.execCmd(cmd)
173
 
                except Exception, exc:
 
175
                except:
 
176
                    tb = format_exc_start()
174
177
                    self.webio.flush()
175
 
                    self.cmdQ.put({"exc":str(exc)})
 
178
                    self.cmdQ.put({"exc": ''.join(tb)})
176
179
                    self.curr_cmd = ''
177
180
 
178
181
def daemonize():
205
208
    lineQ.put({msg['cmd']:msg['text']})
206
209
    return cmdQ.get()
207
210
 
 
211
def format_exc_start(start=0):
 
212
    etype, value, tb = sys.exc_info()
 
213
    tbbits = traceback.extract_tb(tb)[start:]
 
214
    list = ['Traceback (most recent call last):\n']
 
215
    list = list + traceback.format_list(tbbits)
 
216
    list = list + traceback.format_exception_only(etype, value)
 
217
    return ''.join(list)
 
218
 
208
219
if __name__ == "__main__":
209
220
    port = int(sys.argv[1])
210
221
    magic = sys.argv[2]