当它不满足条件时,我需要在线程上引发异常。我想从线程中选择此异常,因此可以杀死所有线程并停止执行。我该怎么办?
到目前为止,我尝试过的是:
def worker(combo, f1_file, f1_db, f1_table):
global f1
# FILE 1
if combo[1] == 1:
print("Entra en file1")
if f1_file != '':
if check_header(f1_file) is None:
raise Exception('Fichero 1 sin cabecera')
else: f1 = read_files(f1_file)
elif f1_db != '' and f1_table != '':
if combo[0] == 'SUPRA Landing':
f1 = read_table_lake(f1_db, f1_table, '')
else:
f1 = read_table_lake(f1_db, f1_table, {'data_date_part': '2019-10-28'})
...
# MAIN
...
for i in range(NUM_THREADS):
try:
t = threading.Thread(target=worker, args=(combos[i], f1_file, f1_db,
f1_table))
threads.append(t)
t.start()
except Exception as e:
print(e)
for x in threads:
x.kill()