I am using threading python module. I want to execute a function which runs an expression entered by a user. I want to wait for it to finish execution or until a timeout period is reached. The following code should timeout after 5 second, but it never times out. def longFunc(): # this expression could be entered by the user return 45 ** 10 ** 1000 thread = threading.Thread(target=longFunc, args=(), daemon=True) thread.start() thread.join(5.0) print("end") # never reaches this point Why is this and how can I fix this behaviour? Should I try to use multiprocessing instead? Continue reading...