Advertisement
ShinkaiShoujo

10 quotes using threading

May 27th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.54 KB | None | 0 0
  1. import threading
  2. from urllib import urlopen
  3. import json
  4.  
  5. f = urlopen('http://fucking-great-advice.ru/api/random')
  6. s = f.read()
  7. json_s = json.loads(s)
  8. #print(json_s['text'])
  9.  
  10. import requests
  11. lock = threading.Lock()
  12. def get_quote(i):
  13.     f = requests.get('http://fucking-great-advice.ru/api/random')
  14.     json_s = f.json()
  15.     lock.acquire()
  16.     print(str(i)+ ') ' + json_s['text'])
  17.     lock.release()
  18.  
  19. thread_list = []
  20. for i in range(0,10):
  21.     thread_list.append(threading.Thread(target=get_quote, args=(i,)))
  22.     thread_list[i].start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement