Workaround for sys.excepthook thread bug (https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1230540&group_id=5470). Call once from __main__ before creating any threads. If using psyco, call psycho.cannotcompile(threading.Thread.run) since this replaces a new-style cla
()
| 60 | |
| 61 | # Patch to make exceptions in threads cause an exception. |
| 62 | def install_thread_excepthook(): |
| 63 | """ |
| 64 | Workaround for sys.excepthook thread bug |
| 65 | (https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1230540&group_id=5470). |
| 66 | Call once from __main__ before creating any threads. |
| 67 | If using psyco, call psycho.cannotcompile(threading.Thread.run) |
| 68 | since this replaces a new-style class method. |
| 69 | """ |
| 70 | import sys |
| 71 | run_old = Thread.run |
| 72 | |
| 73 | def run(*args, **kwargs): |
| 74 | try: |
| 75 | run_old(*args, **kwargs) |
| 76 | except (KeyboardInterrupt, SystemExit): |
| 77 | raise |
| 78 | except: |
| 79 | sys.excepthook(*sys.exc_info()) |
| 80 | Thread.run = run |
| 81 | |
| 82 | |
| 83 | # Exception handler will log unhandled exceptions |