This repository has been archived by the owner on Apr 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |