def enable_thread_profiling(profile_dir, exception_callback=None):
global profiled_thread_enabled, Thread, Process<EOL>if os.path.isdir(profile_dir):<EOL><INDENT>_Profiler.profile_dir = profile_dir<EOL><DEDENT>else:<EOL><INDENT>raise OSError('<STR_LIT>' % profile_dir)<EOL><DEDENT>_Profiler.exception_callback = exception_callback<EOL>Thread = threading.Thread = ProfiledThread<EOL>Process = multiprocessing.Process = ProfiledProcess<EOL>profiled_thread_enabled = True<EOL>
Monkey-patch the threading.Thread class with our own ProfiledThread. Any subsequent imports of threading.Thread
will reference ProfiledThread instead.