summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--thread-ex1.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/thread-ex1.py b/thread-ex1.py
new file mode 100644
index 0000000..522f535
--- /dev/null
+++ b/thread-ex1.py
@@ -0,0 +1,33 @@
+import threading
+import time
+
+exitFlag = 0
+
+class myThread (threading.Thread):
+ def __init__(self, threadID, name, counter):
+ threading.Thread.__init__(self, name=name)
+ 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-One", 1)
+thread2 = myThread(2, "Thread-Two", 2)
+
+# Start new Threads
+thread1.start()
+thread2.start()
+
+print("End of Program. Exiting Main Thread") \ No newline at end of file