import time
import threading
import sys
def recursive_depth(n):
if n <= 0:
return "bottom"
return recursive_depth(n - 1)
def create_large_data():
data = {"level": 0}
current = data
for i in range(100):
current["next"] = {"level": i + 1}
current = current["next"]
large_list = list(range(10000))
a = {"name": "a"}
b = {"name": "b"}
a["ref"] = b
b["ref"] = a
return data, large_list, a
def thread_worker(name, distinct_sleep):
print(f"Thread {name} starting")
time.sleep(distinct_sleep) x = 100
print(f"Thread {name} working")
return x * 2
def run_threads():
threads = []
t1 = threading.Thread(target=thread_worker, args=("T1", 0.5))
t2 = threading.Thread(target=thread_worker, args=("T2", 1.0))
t1.start()
t2.start()
t1.join()
t2.join()
print("Threads finished")
class CustomException(Exception):
pass
def exception_handler():
try:
raise CustomException("oops")
except CustomException as e:
print("Caught expected exception")