Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77224 > unrolled thread
| Started by | Chris Angelico <rosuav@gmail.com> |
|---|---|
| First post | 2014-08-29 02:42 +1000 |
| Last post | 2014-08-29 02:42 +1000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: Thread terminate Chris Angelico <rosuav@gmail.com> - 2014-08-29 02:42 +1000
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-08-29 02:42 +1000 |
| Subject | Re: Thread terminate |
| Message-ID | <mailman.13573.1409244178.18130.python-list@python.org> |
On Fri, Aug 29, 2014 at 2:23 AM, Chris Kaynor <ckaynor@zindagigames.com> wrote: > If what you want is to make sure the error is not printed to stderr, you'll > just need to make sure the thread's run function does not exit with an > exception. The simpliest way to do that would be to wrap the entire thread's > run function in a try...catch statement, like so: > > class Thread(threading.Thread) > ... > except Exception as err: This is actually something where it may be appropriate to catch BaseException, since you are terminating the thread immediately anyway. If you get a KeyboardInterrupt or something, you'll catch it, log it, and end the thread. Note, though, that retaining the actual error object risks resource leakage. You glom onto all sorts of locals, via the backtrace. Unless you're going to handle the exception and then dispose of the whole thread object, I'd advise caution; maybe consider taking a textual snapshot of the backtrace. ChrisA
Back to top | Article view | comp.lang.python
csiph-web