launch a script from python using threading

#!/usr/bin/python

import threading
import time

exitFlag = 0

class myThread (threading.Thread):
   def __init__(self, threadID, name, counter):
      threading.Thread.__init__(self)
      self.threadID = threadID
      self.name = name
      self.counter = counter
   def run(self):
      print "Starting " + self.name
      print_time(self.name, 5, self.counter)
      print "Exiting " + self.name

def print_time(threadName, counter, delay):
   while counter:
      if exitFlag:
         threadName.exit()
      time.sleep(delay)
      print "%s: %s" % (threadName, time.ctime(time.time()))
      counter -= 1

# Create new threads
thread1 = myThread(1, "Thread-1", 1)
thread2 = myThread(2, "Thread-2", 2)

# Start new Threads
thread1.start()
thread2.start()

print "Exiting Main Thread"

Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
python what is running in a thread should you use thread.start or thread.run python python start function as thread python start another python from thread python start another script from thread how to run python program in thread python run another thread thread x.run() python python from threading import thread threading.thread python example run a function in a thread python python threading local example threading spawn python using threading python create thread from thread python run another script in thread python call another program in thread start a thread in python how to run program which already using thread using another thread python threading.thread.start() pythhon access threading function while running python python thread run function python script thread windows python execute thread how to do run code on thread python run python script from another thread start function in a thread python python threading.local example python execute code from main thread threading python run and start run the function with threads in python execute function thread python how to run a method in thread in python import threading python example python execute function in thread python launch thread run function in a thread python run script in new thread in python python threading how to crate a new thread in run command python threading create new thread in run command python run function in main thread python threading start or run python run function in new thread run in new thread python run another script using threading python python run new thread function python threading start function python how to create a thread and run on it threading local python python run function on new thread python run thread start threads in python python how to use threading python start thread python call another python script threading launch thread python python threading threading in python python run script in another thread python run in thread python create thread to run function run as thread python executing python scripts at once with threading how to make section of the code run in a thread python python run function in thread start thread python python start function in thread run function thread python
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source