class ProfiledThread(threading.Thread):

    def run(self):
        profiler = cProfile.Profile()
try:
    return profiler.runcall(threading.Thread.run, self)
finally:
    pass
How can you profile a script?