The .run() method executes any target function belonging to a given thread object that is now active. It normally executes in the background after the .start() method is invoked.


# .run() executing in the background

The .run() method commonly takes the form of the target function passed to the thread_object, if any.


The .run() method can be overridden with different instructions and statements in a separate subclass, like in the example below:

import threading
class CustomThread(threading.Thread):
def run(self):
print("This is my custom run!")
custom_thread = CustomThread()

After the .start() method is called against the custom_thread, the overriden .run() method is executed and the following is printed:

This is my custom run!

Codebyte Example

Choosing whether or not to override the .run() method is a matter of preference. It exists to assist Java developers with learning to use threads in Python. Passing a target function into the .Thread() constructor and then invoking the .start() will achieve the same thing:



Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn Python on Codecademy