Dump the traceback of the current thread into file. Dump the traceback of all threads if all_threads is true. max_threads caps the number of threads dumped.
faulthandler/dump_traceback
dump_traceback