Can we call run() method directly?

Previous
Next

Can we call run() method directly?

  • run() method is pre-defined in Thread class with empty definition.
  • Run() method override by programmer with custom thread logic.
  • Start() method allocates separate thread space to execute run() logic parallel.
  • If we call run() method directly, it will execute from the same thread space sequentially.
from threading import Thread
import time

class Custom(Thread):
    def run(self):
        for i in range(1,11):
            print("custom : " + str(i))
            time.sleep(1)
        return

class Default:
    def main():
        obj = Custom()
        obj.run()
        for i in range(1,11):
            print("default : " + str(i))
            time.sleep(1)
        return

Default.main()
Previous
Next

Add Comment

Courses Enquiry Form