Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- from urllib import urlopen
- import json
- import time
- #f = urlopen('http://fucking-great-advice.ru/api/random')
- #s = f.read()
- #json_s = json.loads(s)
- #print(json_s['text'])
- import requests
- lock = threading.Lock()
- def get_quote(i):
- f = requests.get('http://fucking-great-advice.ru/api/random')
- json_s = f.json()
- lock.acquire()
- #print(str(i)+ ') ' + json_s['text'])
- lock.release()
- import multiprocessing
- thread_list = []
- n = 1000
- start_time = time.time()
- for i in range(0,n):
- p = multiprocessing.Process(target=get_quote,args=(i,))
- thread_list.append(p)
- thread_list[i].start()
- for i in range(0,n):
- thread_list[i].join()
- print(time.time() - start_time)
- thread_list = []
- start_time = time.time()
- for i in range(0,n):
- thread_list.append(threading.Thread(target=get_quote, args=(i,)))
- thread_list[i].start()
- for i in range(0,n):
- thread_list[i].join()
- print(time.time() - start_time)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement