Created
November 10, 2018 00:02
-
-
Save jimywork/12f9cc11de0f80a8a171b5d0a85617c5 to your computer and use it in GitHub Desktop.
Working with 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 time | |
import threading | |
import queue | |
import logging | |
import requests | |
logging.basicConfig( | |
level=logging.DEBUG, | |
format='[%(levelname)s] (%(threadName)-10s) %(message)s', | |
) | |
class Worker(threading.Thread) : | |
def __init__(self, queue, name=None) : | |
super().__init__(name=name) | |
self._queue = queue | |
self._name = name | |
def run(self) : | |
logging.debug("Start {}".format(time.strftime("%H:%M:%S"))) | |
response = requests.get('http://www.google.com') | |
status = response.status_code | |
print(status) | |
@property | |
def name(self) : | |
return self._name | |
if __name__ == '__main__' : | |
eueuq = queue.Queue() | |
threads = [] | |
for i in range(2) : | |
shodan = Worker(eueuq, 'shodan') | |
threads.append(shodan) | |
shodan.start() | |
shodan.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment