Created
April 18, 2016 16:58
-
-
Save Racum/fae3ef4dd98b9a818c34ae090928f97e to your computer and use it in GitHub Desktop.
Test Python's threading module
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
import threading | |
import time | |
import random | |
class MyThread(threading.Thread): | |
def __init__(self, num): | |
self.num = num | |
threading.Thread.__init__(self) | |
def run(self): | |
for count_run in range(5): | |
time.sleep((random.random() * 3) + 0.5) | |
print("Thread %d - Run %d" % (self.num, count_run + 1)) | |
for i in range(2000000): | |
pass | |
mt1 = MyThread(1) | |
mt2 = MyThread(2) | |
mt3 = MyThread(3) | |
mt4 = MyThread(4) | |
mt1.start() | |
mt2.start() | |
mt3.start() | |
mt4.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment