Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77155
| Date | 2014-08-27 20:55 +0200 |
|---|---|
| From | Ervin Hegedüs <airween@gmail.com> |
| Subject | Thread terminate |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13520.1409165718.18130.python-list@python.org> (permalink) |
Hi,
what's the correct way to terminate a thread by itself?
I mean:
class MyThread(threading.Thread):
def __init__(self, queueitem):
threading.Thread.__init__(self)
...
def run(self):
"""pseudo code below"""
try:
self.connect_to_database()
except:
self.terminate("Error when connect to db")
try:
self.create_db_table()
except:
self.terminate("Error when create table")
....
def terminate(self, msg):
self.error = True
self.errormsg = msg
syslog.syslog(syslog.LOG_DEBUG, msg)
raise Exception(msg)
in main():
for q in range(0, 10):
mt = MyThread()
try:
mt.run()
except:
mt.join()
but it doesn't works - the exception showed on stdout only, and
the thread stops of course, but I would like to handle the
exceptions. If I call the join() inside from thread object, then
an exception raised, cause the thread object of Threading module
doesn't allows that...
Any helps are welcome,
greetings:
a.
--
I � UTF-8
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Thread terminate Ervin Hegedüs <airween@gmail.com> - 2014-08-27 20:55 +0200
csiph-web