Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
added python threading example
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAegis committed Sep 30, 2018
1 parent 185678c commit ddf40c0
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lesson02/example3_threading.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
""" Example 3
Threading
"""

import threading
import time


class MyThread(threading.Thread):
""" Example thread class extending the base thread class
Arguments:
threading {[type]} -- [description]
"""

def run(self):
""" Run the thread and log it
"""

print "{} started!".format(self.getName()) # Thread-x started!
time.sleep(1) # Pretend to work for a second
print "{} finished!".format(self.getName()) # "Thread-x finished!"


if __name__ == '__main__':
for x in range(4): # Four times...
mythread = MyThread(name="Thread-{}".format(
x + 1)) # ...Instantiate a thread and pass a unique ID to it
mythread.start() # ...Start the thread
time.sleep(.6) # ...Wait 0.6 seconds before starting another

0 comments on commit ddf40c0

Please sign in to comment.