Skip to content

Commit 3933de1

Browse files
committed
exit on exception thrown
Signed-off-by: Bugen Zhao <[email protected]>
1 parent 9c57ec8 commit 3933de1

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

demo.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,31 @@
11
import logging
22
import threading
3+
import time
34

45
import pandas as pd
56

67

78
def run(*fs):
9+
exceptions = []
10+
threads = []
11+
12+
def catch(f):
13+
try:
14+
f()
15+
except Exception as e:
16+
logging.error(f"Exception occurred: {e}")
17+
exceptions.append(e)
18+
819
for f in fs:
9-
threading.Thread(target=f).start()
20+
thread = threading.Thread(target=lambda: catch(f))
21+
thread.daemon = True # don't wait for this thread to finish
22+
thread.start()
23+
threads.append(thread)
24+
25+
while any(thread.is_alive() for thread in threads):
26+
if exceptions:
27+
raise exceptions[0]
28+
time.sleep(1)
1029

1130

1231
def generate_tick_data():

0 commit comments

Comments
 (0)