Thread terminate
Ervin Hegedüs
airween at gmail.com
Wed Aug 27 14:55:14 EDT 2014
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
More information about the Python-list
mailing list