Skip to content

Instantly share code, notes, and snippets.

@jimywork
Created November 10, 2018 00:02
Show Gist options
  • Save jimywork/12f9cc11de0f80a8a171b5d0a85617c5 to your computer and use it in GitHub Desktop.
Save jimywork/12f9cc11de0f80a8a171b5d0a85617c5 to your computer and use it in GitHub Desktop.
Working with threads
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