Created
March 5, 2017 17:45
-
-
Save bnchdrff/a7e1ed3dbf3b57a3f54ac641b8bd0017 to your computer and use it in GitHub Desktop.
v simple threads
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 os | |
import threading | |
import urllib2 | |
class ThreadHandler(threading.Thread): | |
def __init__(self, blocking_function): | |
threading.Thread.__init__(self) | |
self.runnable = blocking_function | |
def run(self): | |
self.runnable() | |
def get_10_sec(): | |
urllib2.urlopen('https://httpbin.org/delay/10').read() | |
print 'get_10_sec done' | |
def get_5_sec(): | |
urllib2.urlopen('https://httpbin.org/delay/5').read() | |
print 'get_5_sec done' | |
def run_the_thready(): | |
print 'thread1 = ThreadHandler(get_10_sec)' | |
thread1 = ThreadHandler(get_10_sec) | |
print 'thread1.start()' | |
thread1.start() | |
print 'thread2 = ThreadHandler(get_5_sec)' | |
thread2 = ThreadHandler(get_5_sec) | |
print 'thread2.start()' | |
thread2.start() | |
print 'thread1.join()' | |
thread1.join() | |
print 'thread2.join()' | |
thread2.join() | |
print 'end of run_the_thready' | |
print 'run_the_thready()' | |
run_the_thready() | |
print 'done' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment